4 ms·
The results he got for C and C++ make no sense and I question what optimization flag was actually used if any. From the looks of it, he uses "-O" which is equiv
by banachtarski 8y ago
The results he got for C and C++ make no sense and I question what optimization flag was actually used if any. From the looks of it, he uses "-O" which is equivalent to "-O1" which is really not the flag you want (this optimizes for both time and code size).
*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.
- fgimian 8y agoThanks so much for your comment. I had actually tried -O3 during my tests and didn't notice a huge difference in this particular example. 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?
- lallysingh 8y agoHow much optimization do you expect a loop with a simple addition to have? It doesn't seem a representative workload for an optimizer.
- rdc12 8y agoExcept it is not a loop[1], but a non-tail recursive function (with dual calls), if the compiler can optimise that to a loop that is actually impressive. 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.
- mbel 8y ago> Most likely function call overhead Quite likely: https://godbolt.org/g/xGkCyA 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.