Fix <bitset> benchmark correctness by AlexGuteniev · Pull Request #4817 · microsoft/STL (original) (raw)

I see more things to do with bitset regarding performance, but first let's fix the current benchmark.

Fortunately, the discovered issues didn't have impact on results, and on performance decisions.

Add DoNotOptimize to input

Should use this to prevent compiler making the benchmarked function or its part constant.
Currently the compiler doesn't do this, but it might improve in the future

Make 512 case as large

Small cases were initialized with uint64_t which was not enough to initialize 512 bit bitset.

The 512 rows in the benchmark improved, but it is gooseberries vs watermelons: small cases have inner loop whereas large doesn't.

(The loop in small cases is to defeat branch prediction for the cases of branchy implementation activation. It is not needed for larger bitsets, as these would be vectorized, and if they wouldn't, the amount of bits should be enough to overflow the branch prediction)