5 ms·
Just to underline the futility of this, if you are clever you can let the compiler do it. https://everything2.com/title/C%252B%252B%253A+computing+Fibonacci+nu
by rothron 8y ago
Just to underline the futility of this, if you are clever you can let the compiler do it.
https://everything2.com/title/C%252B%252B%253A+computing+Fibonacci+numbers+at+compile+time https://everything2.com/title/C%252B%252B%253A+computing+Fib...
- eesmith 8y agoThe benchmark includes a C++ constexpr version, at https://github.com/drujensen/fib/blob/master/fib-constexpr.cpp https://github.com/drujensen/fib/blob/master/fib-constexpr.c... , with timing numbers under the section "Optimized code that breaks the benchmark" and the comment "all benchmarks will have some caveat."
- larkeith 8y agoSomewhat off topic, but I love the fact that the first post regarding compile-time Fibonacci in C++ was submitted in 2000, another user expanded on the original in 2008, and now it's being usefully referenced in 2018. I stumbled across Everything2 recently, but in many ways it strikes me as a tiny bit of the golden age of the internet, unexpectedly preserved.