|
eztimer
Easy timing of C++ functions
|
The eztimer library implements a simple timing framework for C++ functions, mostly intended for testing algorithms in other tatami libraries. Users can supply multiple functions and eztimer will run them over multiple iterations in randomized order. The first "burn-in" iteration is also discarded to avoid any initialization effects. For convenience, we support both a per-function and overall cap on the runtime.
Check out the reference documentation for more details.
The check argument to eztimer::time() ensures that the result of each function call has a user-visible effect on the program. This prevents the compiler from optimizing away the function call entirely. In the example above, we threw an error if the result of each call did not follow our non-zero expectation. We could also be more concrete if we expected all functions to return the same result:
Another option is to simply print the result to standard output. This may also be generally useful to track the progress of time() for long-running functions.
As for the timing itself, we just measure the wall time taken to execute each function. We don't bother with the sys/user distinction, or try to measure cycles, or anything particularly complicated. It seems pointless to try to be too smart here as execution time depends on so many factors - if you want generalizable conclusions about performance, the best approach is to repeat the timings on different machines.
FetchContentIf you're using CMake, you just need to add something like this to your CMakeLists.txt:
Then you can link to tatami to make the headers available during compilation:
find_package()You can install the library by cloning a suitable version of this repository and running the following commands:
Then you can use find_package() as usual:
If you're not using CMake, the simple approach is to just copy the files the include/ subdirectory - either directly or with Git submodules - and include their path during compilation with, e.g., GCC's -I. This also requires the external dependencies listed in extern/CMakeLists.txt as well as Zlib.