I\'ve developed a simple program and want to evaluate its runtime performance on a real machine, e.g. my MacBook. The source code goes:
#include
Benchmarking is hard!
Short answer: use google benchmark
Long answer: There are many things that will interfere with timings.
The only way to avoid these effects are to disable CPU scaling, to do "cache-flush" functions (normally just touching a lot of memory before starting), running at high priority, and locking yourself to a single CPU. Even after all that, your timings will still be noisy, so the last thing is simply to repeat a lot, and use the average.
This why tools like google benchmark are probably your best bet.
video from CPPCon
Also available live online