Closed ts826848 closed 3 years ago
In case you're interested, here's an Excel file with the benchmark numbers: pow-benches.xlsx
The quality of this PR astonished me. Definitely interested in the benchmark graph!
Thank you for this valuable contribution.
Out of curiosity, what library were you using for your benchmarks?
Thanks! To be honest, it was actually a bit more of a rabbit hole than I initially expected, but it was an enjoyable process nevertheless.
I used Google Benchmark. I cloned the repo into the folder where I wrote the benchmark file so it could use the same compiler/flags as the benchmark file. I'd get linker errors if I installed it using the package manager.
Multiple pow() implementations were considered:
Based on quick and dirty benchmarks on a 2015 Retina Pro 2.8 GHz (source code in [1, 2], results in [3]), implementation 4 was chosen since it resulted in good benchmark numbers for a wide range of exponents for both GCC and Clang.
Some implementation notes:
return pow(1 / x, static_cast<unsigned long long>(-y));
[1]: CMakeLists.txt
[2]: main.cpp
[3]: Benchmark results: