This is literally why I prefer NOT using magic libraries for benchmarks. People often does not get, why I am fine with compiler optimizing stuff out and me checking assembly to realize what really happens, but I totally prefer it that way. The conclusion is actually very close to what I think: Just avoid as much magic as possible when benchmarking and indeed just go do things by hand. If you really need that benchmarking you pretty much better off knowing assembly already anyways...
- If you are going to copy (by value) an object that is either _large_ or has an expensive copy constructor , use a unique_ptr instead of a stack-based value. - Sometimes you copy without realizing it.
The title is too click-baity, but I like the conclusion 😂 Benchmarks are super hard and are frequently deceiving.
This is literally why I prefer NOT using magic libraries for benchmarks. People often does not get, why I am fine with compiler optimizing stuff out and me checking assembly to realize what really happens, but I totally prefer it that way.
The conclusion is actually very close to what I think: Just avoid as much magic as possible when benchmarking and indeed just go do things by hand. If you really need that benchmarking you pretty much better off knowing assembly already anyways...
- If you are going to copy (by value) an object that is either _large_ or has an expensive copy constructor , use a unique_ptr instead of a stack-based value.
- Sometimes you copy without realizing it.