*edit: with O2 I get a dramatic improvement and the C and C++ versions compile to essentially the same disassembly. Using O1 is definitely not going to produce an apples to apples comparison.
*edit: with O2 I get a dramatic improvement and the C and C++ versions compile to essentially the same disassembly. Using O1 is definitely not going to produce an apples to apples comparison.
fots ~ $ gcc -O -o fib fib.c
fots ~ $ time ./fib
433494437
real 0m0.749s
user 0m0.743s
sys 0m0.003s
fots ~ $ gcc -O3 -o fib fib.c
fots ~ $ time ./fib
433494437
real 0m0.747s
user 0m0.742s
sys 0m0.003s
fots ~ $ gcc -O2 -o fib fib.c
fots ~ $ time ./fib
433494437
real 0m0.741s
user 0m0.737s
sys 0m0.003s
Clearly this is just a little mathematical algorithm and more real-world problems would likely produce a more dramatic difference.
What sort of differences did you see on your end?
Most likely function call overhead (and in the slower cases, interpreter overhead) is probably what is being measured in the best case.
[1] In that it won't be a jump and check style loop.
Quite likely: https://godbolt.org/g/xGkCyA although it really depends on the compiler (gcc is smarter here). He also seems to be benchmarking printing more than anything else (hence the difference between C and C++).
Without versions of the compilers and explained methods of measurement, the results posted on the blog are more anecdotal knowledge than any kind of benchmark.