drujensen / fib
- суббота, 29 сентября 2018 г. в 00:16:40
JavaScript
Performance Benchmark of top Github languages
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:
Last benchmark was ran on September 25th, 2018
Language | Time, s | Compile | Run |
---|---|---|---|
Nim | 4.622 | nim cpp -d:release fib.nim |
time ./fib |
Crystal | 5.687 | crystal build --release fib.cr |
time ./fib |
C++ | 5.751 | g++ -O3 -o fib fib.cpp |
time ./fib |
C | 6.258 | gcc -O3 -o fib fib.c |
time ./fib |
Rust | 6.567 | rustc -O fib.rs |
time ./fib |
D | 6.993 | ldc2 -O3 -release -flto=full -of=fib fib.d |
time ./fib |
Swift | 10.307 | swiftc -O -g fib.swift |
time ./fib |
Go | 10.600 | go build fib.go |
time ./fib |
OCaml | ocamlopt -O3 -o fib fib.ml |
time ./fib |
|
Haskell | ghc -O3 -o fib fib.hs |
time ./fib |
|
Fortran | x.xxx | gfortran -O3 -o fib fib.f03 |
time ./fib |
Language | Time, s | Compile | Run |
---|---|---|---|
Java | 7.447 | javac Fib.java |
time java Fib |
C# | 7.874 | dotnet build -c Release -o ./bin |
time dotnet ./bin/fib.dll |
C# (Mono) | 12.596 | mcs fib.cs |
time mono fib.exe |
Language | Time, s | Run |
---|---|---|
Dart | 10.467 | time dart fib.dart |
Julia | 10.799 | time julia fib.jl |
Node | 18.874 | time node fib.js |
Elixir | 69.101 | time elixir fib.exs |
NOTE: These languages include compilation time which should be taken into consideration when comparing.
Language | Time, s | Run |
---|---|---|
Ruby | 195.601 | time ruby fib.rb |
Php | 206.346 | time php fib.php |
Python | 502.036 | time python fib.py |
Python3 | 758.681 | time python3 fib.py |
Perl | 1133.131 | time perl fib.pl |
Perl 6 | TODO | time perl6 fib.p6 |
R | 1796.495 | time r -f fib.r |
Tcl | TODO | time tclsh fib.tcl |
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.
Language | Time, s | Compile | Run |
---|---|---|---|
Go (mem) | 0.005* | go build -o fib fib-mem.go |
time ./fib |
Nim (mem) | 0.006* | nim cpp -d:release fib_mem.nim |
time ./fib_mem |
C++ (constexpr) | 0.086* | g++-8 -O3 -o fib fib-constexpr.cpp |
time ./fib |
Node (mem) | 0.112* | time node fib-mem.js |
|
Python (lru_cache) | TODO | time python3 fib-cache.pu |
|
Lua (mem) | TODO | time 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