Skip to content

Repository files navigation

Recursive Fibonacci Benchmark using top languages on Github

Top 10: JavaScript, Java, Python, Ruby, Php, C++, C#, C, Go reference

Others: Crystal, Rust, Swift, Mono, Elixir, Perl, R, Julia, D, Nim

This code performs a recursive fibonacci to the 46th position with the result of 2,971,215,073.

All tests are run on:

  • iMac (Retina 5K, 27-inch, Late 2015)
  • OS: macOS High Sierra 10.13.6
  • Processor: 3.2 GHz Intel Core i5
  • Memory: 16 GB 1867 MHz DDR3

Last benchmark was ran on September 25th, 2018

Natively compiled, statically typed

LanguageTime, sCompileRun
Nim4.622nim cpp -d:release fib.nimtime ./fib
Crystal5.687crystal build --release fib.crtime ./fib
C++5.751g++ -O3 -o fib fib.cpptime ./fib
C6.258gcc -O3 -o fib fib.ctime ./fib
Rust6.567rustc -O fib.rstime ./fib
D6.993ldc2 -O3 -release -flto=full -of=fib fib.dtime ./fib
Swift10.307swiftc -O -g fib.swifttime ./fib
Go10.600go build fib.gotime ./fib
OCamlocamlopt -O3 -o fib fib.mltime ./fib
Haskellghc -O3 -o fib fib.hstime ./fib
Fortranx.xxxgfortran -O3 -o fib fib.f03time ./fib

VM compiled bytecode, statically typed

LanguageTime, sCompileRun
Java7.447javac Fib.javatime java Fib
C#7.874dotnet build -c Release -o ./bintime dotnet ./bin/fib.dll
C# (Mono)12.596mcs fib.cstime mono fib.exe

VM compiled before execution, mixed/dynamically typed

LanguageTime, sRun
Dart10.467time dart fib.dart
Julia10.799time julia fib.jl
Node18.874time node fib.js
Elixir69.101time elixir fib.exs

NOTE: These languages include compilation time which should be taken into consideration when comparing.

Interpreted, dynamically typed

LanguageTime, sRun
Ruby195.601time ruby fib.rb
Php206.346time php fib.php
Python502.036time python fib.py
Python3758.681time python3 fib.py
Perl1133.131time perl fib.pl
Perl 6TODOtime perl6 fib.p6
R1796.495time r -f fib.r
TclTODOtime tclsh fib.tcl

Optimized code that breaks the benchmark

The following code examples use techniques that break the benchmark. They do not perform the same internal tasks as the other examples so are not a good apples to apples comparisons. It demonstrates that all benchmarks will have some caveat.

LanguageTime, sCompileRun
Go (mem)0.005*go build -o fib fib-mem.gotime ./fib
Nim (mem)0.006*nim cpp -d:release fib_mem.nimtime ./fib_mem
C++ (constexpr)0.086*g++-8 -O3 -o fib fib-constexpr.cpptime ./fib
Node (mem)0.112*time node fib-mem.js
Python (lru_cache)TODOtime python3 fib-cache.pu
Lua (mem)TODOtime luajit fib-mem.lua

NOTE: The C++ (constexpr) is using a constexpr which optimizes the recursive call to a constant. It was provided by Ole Christian Eidheim. The Go (mem) is using memoization. It was provided by Alexander F. Rødseth. The Node (mem) is another example using memoization. It was provided by YSTYLE-L.X.Y The Nim (mem) version is provided by PMunch

Versions

  • go version go1.11 darwin/amd64
  • g++-8 (Homebrew GCC 8.2.0) 8.2.0
  • crystal Crystal 0.26.1 (2018-08-27) LLVM: 6.0.1
  • g++ Apple LLVM version 10.0.0 (clang-1000.11.45.2)
  • gcc Apple LLVM version 10.0.0 (clang-1000.11.45.2)
  • nim Nim Compiler Version 0.18.0 [MacOSX: amd64]
  • swiftc Apple Swift version 4.2 (swiftlang-1000.11.37.1 clang-1000.11.45.1)
  • rustc 1.29.0
  • javac 10.0.1
  • mcs Mono C# compiler version 5.12.0.226
  • dotnet 2.1.4
  • dart Dart VM version: 2.0.0 (Fri Aug 3 10:53:23 2018 +0200)
  • julia version 0.6.3
  • node v9.4.0
  • elixir Elixir 1.7.3 (compiled with Erlang/OTP 21)
  • ruby 2.5.1p57 (2018-03-29 revision 63029)
  • php 7.1.16 (cli) (built: Apr 1 2018 13:14:42)
  • python 2.7.15
  • python3 3.7.0
  • perl 5, version 26, subversion 2 (v5.26.2)
  • r version 3.5.0 (2018-04-23)
  • lcd2 the LLVM D compiler (1.11.0)

Caveats

Fibonacci Benchmark

About

Performance Benchmark of top Github languages

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages