Re:Why Crystal Is My Next Language
by lallysingh on Monday June 11, 2018 @12:36AM
(#17281829)
How much optimization do you expect a loop with a simple addition to have? It doesn't seem a representative workload for an optimizer.
Except 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.
> Most likely function call overhead
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.
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?