3 ms·
A few observations: - on my machine, C++ is slower than C. - I thought that in Julia, startup and compile time could be a factor, but they're pretty negligibl
by FabHK 8y ago
A few observations:
- on my machine, C++ is slower than C.
- I thought that in Julia, startup and compile time could be a factor, but they're pretty negligible (maybe 1 to 5% or so of the runtime, for Julia 0.7).
- Without the -O3 switch, the runtime more or less doubles for C and C++, making these languages slower than Swift, Go, Java, Dart, Julia, etc. That surprised me.
- olzd 8y agoThe -O3 switch removes a recursive call, among other things (https://godbolt.org/z/oS3Cju https://godbolt.org/z/oS3Cju).
- FabHK 8y agoInteresting. (Awesome compiler explorer website, btw). The Julia version (whose runtime is halfway between the C versions with vs without -O3) contains both recursive calls, FWIW.
- shele 8y agoYeah, startup and compilation time in Julia is not a big deal. One could even make the compiler work a bit harder, but you would have to ask a lawyer if this still counts as recursion ;-) julia> function fib(::Val{n}) where n if n <= 1 return 1 end return fib(Val(n - 1)) + fib(Val(n - 2)) end julia> fib(n) = fib(Val(n)) julia> @time fib(46) # Compilation and execution 0.095409 seconds