According to Google, you will rarely ever need to run microbenchmarks. Still, some developers will find it useful when they need to see if a piece of code they’re working on is truly worth it. While there are tools available to run microbenchmarks, Google thought it would be a good idea to make its own.
Google announced today that it has created a new microbenchmarking tool called benchmark. The tool is built on a C++ library and was inspired by googletest. The tool “supports value- and type-parameterized benchmarks, various options for running the benchmarks including multithreading, and custom report generation.”
While benchmark is based on googletest, Google notes that there is a major difference between the two. In benchmark, benchmarks are not automatically discovered like they are in googletest. This isn’t a bad thing though as Google notes the lack of automatic discovery “allows greater flexibility in terms of how benchmarks are run, and the parameters that are used by the benchmark.”
Here’s what benchmark looks like:
As is the case with most of these tools, benchmark is an open source project. You can check it out on github and start contributing. If you just want to use it, you’ll also find test code on its github page as well.