Monday, May 4, 2015

Go: fib

Go code is relatively low-level since it does not have "foreach over range" syntax construct:

Results are not as impressive for a systems language: 2.38 seconds. And it lays below Rust but under Haskell:
  • C# - 1.26
  • D (DMD) - 1.3
  • F# - 1.38
  • Nemerle - 1.45
  • Rust - 1.66
  • Go - 2.38
  • Haskell - 2.8
  • Clojure - 9
  • Erlang - 17
  • Ruby - 60
  • Python - 120

2 comments:

Павел Мартынов said...

What about reference C implementaion? Code for VS2013, in Release configuration 0.87 sec on my machine.

#include
#include

int fib(int n){
if (n < 2)
return n;
return fib(n - 1) + fib(n - 2);
}

int main()
{
clock_t begin = clock();

for (int n = 0; n < 40; n++) {
printf("fib (%d) = %d\n", n, fib(n));
}

clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
printf("elapsed: %f secs\n", elapsed_secs);
return 0;
}

Vasily said...

Give me a x64 exe and I'll run it on the machine I run all the benchmarks before.