Showing posts with label mono. Show all posts
Showing posts with label mono. Show all posts

2015-03-03

Prime Number Generator Benchmark

Today we're gonna benchmark about prime number generator (without sieve and prime library). The spec is generating all prime number below 10 million and outputting every 100k-th prime found. As usual, the source can be found on my dropbox (folder: prime). The benchmark performed on 64-bit Linux, i3-4150, 16GB RAM and non-SSD disk.

# desired output:
1299721
2750161
4256249
5800139
7368791
8960467

$ g++ --version
g++ (GCC) 4.9.2 20150204 (prerelease)
$ time g++ -std=c++11 prime.cpp
CPU: 0.20s      Real: 0.23s     RAM: 50232KB
$ time ./a.out
CPU: 2.94s      Real: 2.95s     RAM: 6592KB
$ time g++ -O2 -std=c++11 prime.cpp
CPU: 0.21s      Real: 0.23s     RAM: 51912KB
$ time ./a.out
CPU: 0.85s      Real: 0.85s     RAM: 6616KB

$ clang++ --version
clang version 3.5.1 (tags/RELEASE_351/final)
$ time clang++ -std=c++11 prime.cpp
CPU: 0.19s      Real: 0.23s     RAM: 46792KB
$ time ./a.out
CPU: 2.93s      Real: 2.94s     RAM: 6488KB
$ time clang++ -O2 -std=c++11 prime.cpp
CPU: 0.20s      Real: 0.22s     RAM: 50484KB
$ time ./a.out
CPU: 0.84s      Real: 0.84s     RAM: 6636KB

$ go version
go version go1.4.1 linux/amd64
$ time go build prime.go
CPU: 0.11s      Real: 0.12s     RAM: 30364KB
$ time ./prime
CPU: 2.48s      Real: 2.49s     RAM: 20412KB

$ javac -version
javac 1.7.0_75
$ time javac prime.java
CPU: 0.73s      Real: 0.44s     RAM: 47464KB
$ time java prime
CPU: 1.21s      Real: 1.18s     RAM: 104580KB

$ javac -version
javac 1.8.0_40
$ time javac prime.java

CPU: 0.96s      Real: 0.45s     RAM: 59860KB
$ time java prime
CPU: 1.23s      Real: 1.19s     RAM: 104716KB

$ ruby --version
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
$ time ruby prime.rb
CPU: 20.97s     Real: 20.99s    RAM: 14388KB

rbx --version
rubinius 2.5.2.c85 (2.1.0 e8a24276 2015-02-23 3.5.1 JI) [x86_64-linux-gnu]
$ time rbx prime.rb
CPU: 14.20s     Real: 14.15s    RAM: 54004KB

$ jruby --version
jruby 9.0.0.0-SNAPSHOT (2.2.0p0) 2015-02-24 2a3dc1f OpenJDK 64-Bit Server VM 24.75-b04 on 1.7.0_75-b13 +jit [linux-amd64]
$ time jruby prime.rb
CPU: 38.79s     Real: 36.41s    RAM: 298688KB

$ node --version
v0.10.36
$ time node prime.js
CPU: 1.61s      Real: 1.62s     RAM: 24796KB

$ pacman -Qo `which jsc-3`
/usr/bin/jsc-3 is owned by webkitgtk 2.4.8-1
$ time jsc-3 prime.js
CPU: 2.30s      Real: 2.31s     RAM: 22008KB

js24 --help| grep Version
Version: JavaScript-C24.2.0
$ time js24 prime.js
CPU: 1.19s      Real: 1.24s     RAM: 15488KB

$ echo | rhino
Rhino 1.7 release 4 2014 07 01
$ time rhino prime.js
CPU: 56.23s     Real: 55.72s    RAM: 873048KB

$ echo | jjs -version
nashorn 1.8.0_40

$ time jjs prime.js
CPU: 23.36s     Real: 22.28s    RAM: 448144KB

$ php --version
PHP 5.6.5 (cli) (built: Jan 22 2015 18:29:09) 
$ time php prime.php
CPU: 36.70s     Real: 36.77s    RAM: 111488KB

$ hhvm --version
HipHop VM 3.5.0 (rel) Compiler: 1422366928_067131079
$ time hhvm -v Eval.Jit=true prime.php 
CPU: 5.92s      Real: 11.14s    RAM: 98288KB

$ python --version
Python 3.4.2
$ time python prime.py
CPU: 78.33s     Real: 78.51s    RAM: 33476KB

$ pypy --version 
Python 2.7.8 (10f1b29a2bd2, Feb 05 2015, 16:50:17) [PyPy 2.5.0 with GCC 4.9.2 20141224 (prerelease)]
$ time pypy prime.py
CPU: 3.66s      Real: 4.14s     RAM: 84180KB

$ lua -v
Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
$ time lua prime.lua
CPU: 22.16s     Real: 22.19s    RAM: 18628KB

$ luajit -v
LuaJIT 2.0.3 -- Copyright (C) 2005-2014 Mike Pall. http://luajit.org/
$ time luajit prime.lua
CPU: 6.64s      Real: 6.65s     RAM: 10360KB

$ mcs --version
Mono C# compiler version 3.12.0.0
$ time mcs prime.cs
CPU: 0.35s      Real: 0.36s     RAM: 39704KB
$ time mono prime.exe 
CPU: 1.78s      Real: 1.79s     RAM: 16368KB

$ dart --version
Dart VM version: 1.8.5 (Tue Jan 13 12:44:14 2015) on "linux_x64"
$ time dart prime.dart
CPU: 1.37s      Real: 1.38s     RAM: 31604KB

$ crystal --version
Crystal 0.6.1 [0162f84] (Mon Mar 16 15:22:20 UTC 2015)
$ time crystal prime.cr
CPU: 2.53s      Real: 2.62s     RAM: 28552KB
$ time crystal prime.cr --release
CPU: 1.18s      Real: 1.23s     RAM: 36784KB

$ julia --version
julia version 0.3.6
$ time julia prime.jl
CPU: 3.09s      Real: 3.12s     RAM: 71576KB

$ nim --version
Nim Compiler Version 0.10.2 (2014-12-31) [Linux: amd64]
$ time nim c prime.nim
CPU: 0.66s      Real: 0.69s     RAM: 44728KB
$ time ./prime
CPU: 7.65s      Real: 7.67s     RAM: 12224KB
$ time nim c -d:release prime.nim
CPU: 1.36s      Real: 1.36s     RAM: 55376KB
$ time ./prime
CPU: 2.44s      Real: 2.45s     RAM: 12160KB

$ rustc --version
rustc 1.0.0-dev (built 2015-02-23)
$ time rustc prime.rs
CPU: 0.36s      Real: 1.76s     RAM: 95960KB
$ time ./prime 
CPU: 3.75s      Real: 3.76s     RAM: 6196KB
$ time rustc -O prime.rs
CPU: 0.34s      Real: 0.38s     RAM: 96764KB
$ time ./prime 
CPU: 1.03s      Real: 1.04s     RAM: 6224KB

$ gnatmake --version
GNATMAKE 4.9.2 20150304 (prerelease)
$ time gnatmake prime.adb
CPU: 0.40s      Real: 0.44s     RAM: 51540KB
$ time ./prime
CPU: 5.85s      Real: 5.86s     RAM: 5488KB
$ rm prime prime.o prime.ali; time gnatmake -O2 prime.adb
CPU: 0.86s      Real: 0.91s     RAM: 57084KB
$ time ./prime
CPU: 1.27s      Real: 1.27s     RAM: 5348KB

$ fpc -version
Free Pascal Compiler version 2.6.4 [2014/03/12] for x86_64
$ time fpc prime.pas
CPU: 0.01s      Real: 0.02s     RAM: 10636KB
$ time ./prime
CPU: 3.42s      Real: 3.42s     RAM: 6688KB
$ time fpc -O2 prime.pas
CPU: 0.01s      Real: 0.02s     RAM: 10568KB
$ time ./prime
CPU: 3.00s      Real: 3.02s     RAM: 6688KB

And the summary:

Compiler / InterpreterLanguageCompile DurationCompile RAMRuntime DurationRuntime RAMTotal Duration
g++C++20050232294065923140
g++ (-O2)C++2105191285066161060
clang++C++19046792293064883120
clang++ (-O2)C++2005048484066361040
goGo110303642480204122590
javac, javaJava7304746412101045801940
rubyRuby209701438820970
rbxRuby142005400414200
jrubyRuby3879029868838790
nodeJavaScript1610247961610
jsc-3JavaScript2300220082300
js24JavaScript1190154881190
rhinoJavaScript5623087304856230
jjsJavaScript2336044814423360
phpPHP3670011148836700
hhvmPHP5920982885920
python3Python 3783303347678330
pypyPython 23660841803660
luaLua221601862822160
luajitLua6640103606640
mcsC#350397041780163682130
dartDart1370316041370
crystalCrystal2530285522530
crystal (--release)Crystal1180367841180
juliaJulia3090715763090
nimNimrod660447287650122248310
nim (-d:release)Nimrod1360553762440121603800
rustcRust36095960375061964110
rustc (-O)Rust34096764103062241370
gnatmakeAda40051540585054886250
gnatmake (-O2)Ada86057084127053482130
fpcObjectPascal1010636342066883430
fpc (-O2)ObjectPascal1010568300066883010

Note #1: PH7 failed to give any output within 1 minute.
Note #2: IO failed to give complete output within 2 minutes.
Note #3: Nimrod caches the compile process, so the second time compile are less than 100ms
Note #4: Potion failed to give complete output within 2 minutes.
Note #5: Gnatmake caches the compile process, so the second time compile are less than 10ms, but it doesn't overwrite when different flag used (-O2 for example).
Note #6: Some languages can be compiled, and some other can be executed directly using certain command, but I choose one that I learned first (but I will benchmark both method when I have much free time)
Note #7: Compile cache deleted before every (3) benchmark run, the value taken are the median.

Changelog:
2015-03-03: benchmark published
2015-03-xx: Lua, C# (mcs), and Dart added
2015-03-17: Crystal, Julia, and Nimrod (nim) added
2015-03-18: ObjectPascal (fpc), Ada (gnat), and Nashorn (jjs) added








2015-02-26

Numeric CombSort Benchmark update!

As I've written before, CombSort are quite good sort algorithm. Let's compare this algorithm when implemented in various programming language. The benchmark should not use any other built-in function other than array generation and printing. The benchmark uses AMD A8-6600K, 16GB RAM with Non-SSD disk.

$ alias | grep 'alias time'
alias time='/usr/bin/time -f "\nCPU: %Us\tReal: %es\tRAM: %MKB"'
$ time --version
GNU time 1.7

g++ --version
g++ (GCC) 4.9.2 20141224 (prerelease)
$ time g++ comb.cpp
CPU: 0.05s      Real: 0.12s     RAM: 19428KB
$ time ./a.out
CPU: 1.94s      Real: 1.97s     RAM: 79804KB
$ time g++ -O2 comb.cpp
CPU: 0.07s      Real: 0.11s     RAM: 21260KB
$ time ./a.out
CPU: 0.88s      Real: 0.90s     RAM: 79804KB

clang --version
clang version 3.5.1 (tags/RELEASE_351/final)
$ time clang++ comb.cpp
CPU: 0.05s      Real: 0.08s     RAM: 33564KB
$ time ./a.out
CPU: 1.83s      Real: 1.86s     RAM: 79764KB
$ time clang++ -O2 comb.cpp
CPU: 0.08s      Real: 0.14s     RAM: 37860KB
$ time ./a.out
CPU: 0.89s      Real: 0.91s     RAM: 79804KB

java -version
java version "1.7.0_71" 
$ time javac comb.java
CPU: 1.05s      Real: 0.73s     RAM: 65952KB
$ time java comb
CPU: 1.32s      Real: 1.32s     RAM: 110488KB

php --version
PHP 5.6.4 (cli) (built: Dec 17 2014 21:45:04)
$ time php comb.php
CPU: 102.69s    Real: 104.20s   RAM: 2497508KB

hhvm --version
HipHop VM 3.5.0 (rel)
$ time hhvm -v Eval.Jit=true comb.php 
CPU: 12.56s     Real: 14.83s    RAM: 362488KB

ruby --version
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]
$ time ruby comb.rb
CPU: 52.87s     Real: 53.02s    RAM: 87892KB

rbx --version
rubinius 2.5.2 (2.1.0 7a5b05b1 2015-01-30 3.5.1 JI) [x86_64-linux-gnu]
$ time rbx comb.rb
CPU: 74.89s     Real: 74.30s    RAM: 135320KB

node --version
v0.10.35
$ time node comb1.js
CPU: 2.64s      Real: 2.64s     RAM: 92240KB
$ time node comb2.js
CPU: 2.68s      Real: 2.72s     RAM: 140612KB

rhino < /dev/null 
Rhino 1.7 release 4 2014 07 01
$ rhino comb2.js
CPU: 87.39s     Real: 61.16s    RAM: 1993848KB

$ pacman -Qo `which jsc-3`
/usr/bin/jsc-3 is owned by webkitgtk 2.4.8-1
$ time jsc-3 comb1.js
CPU: 23.74s     Real: 23.93s    RAM: 93740KB
$ time jsc-3 comb2.js
CPU: 18.99s     Real: 19.16s    RAM: 181644KB

js24 --help | grep Version
Version: JavaScript-C24.2.0
$ time js24 --ion-eager comb1.js
CPU: 2.13s      Real: 2.15s     RAM: 89688KB
$ time js24 --ion-eager comb2.js
CPU: 1.53s      Real: 1.58s     RAM: 92384KB

go version
go version go1.4.1 linux/amd64
$ time go build comb.go 
CPU: 0.14s      Real: 0.17s     RAM: 31568KB
$ time ./comb
CPU: 1.10s      Real: 1.14s     RAM: 79824KB

rustc --version
rustc 1.0.0-dev
$ time rustc comb.rs
CPU: 0.39s      Real: 0.49s     RAM: 106844KB
$ time ./comb
CPU: 10.62s     Real: 10.71s    RAM: 86020KB
$ time rustc -O comb.rs
CPU: 0.41s      Real: 0.49s     RAM: 110204KB
$ time ./comb
CPU: 0.97s      Real: 0.99s     RAM: 86108KB

scala -version
Scala code runner version 2.11.5 -- Copyright 2002-2013, LAMP/EPFL
$ time scala comb.scala
CPU: 5.43s      Real: 6.30s     RAM: 206088KB
$ time scalac comb.scala
CPU: 10.62s     Real: 7.00s     RAM: 143460KB
$ time scala Comb
CPU: 5.49s      Real: 5.05s     RAM: 206300KB

python --version
Python 3.4.2
$ time python comb1.py
CPU: 90.47s     Real: 90.83s    RAM: 403192KB
$ time python comb2.py
CPU: 106.82s    Real: 107.26s   RAM: 87248KB

pypy --version
Python 2.7.8 (c6ad44ecf5d8, Nov 18 2014, 18:04:31) [PyPy 2.4.0 with GCC 4.9.2]
$ time pypy comb1.py
CPU: 5.34s      Real: 5.40s     RAM: 136764KB
$ time pypy comb2.py
CPU: 5.85s      Real: 6.04s     RAM: 204588KB

mcs --version
Mono C# compiler version 3.12.0.0
$ time mcs -o+ comb.cs
CPU: 0.44s      Real: 0.47s     RAM: 45908KB
$ time ./comb.exe
CPU: 1.38s      Real: 1.41s     RAM: 90472KB

lua -v
Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
$ time lua comb.lua
CPU: 65.64s     Real: 65.81s    RAM: 264096KB

luajit -v
LuaJIT 2.0.3 -- Copyright (C) 2005-2014 Mike Pall.
$ time luajit comb.lua
CPU: 6.30s      Real: 6.34s     RAM: 132964KB

dart --version
Dart VM version: 1.8.5 (Tue Jan 13 12:44:14 2015) on "linux_x64"
$ time dart scomb.dart
CPU: 2.12s      Real: 2.24s     RAM: 93392KB

The code can be found on my dropbox (folder: num-comb), and here's the summary:

Compiler / InterpreterLanguageCompile DurationCompile RAMRuntime DurationRuntime RAMTotal Duration
g++ (debug)C++50194281940798041990
g++ (-O2)C++702126088079804950
clang++ (debug)C++50335641830797641880
clang++ (-O2)C++803786089079804970
javac, javaJava10506595213201104882370
phpPHP1026902497508102690
hhvmPHP1256036248812560
rubyRuby528708789252870
rbxRuby7489013532074890
node (typed array)Javascript2640922402640
node (untyped array)Javascript26801406122680
rhino (untyped array)Javascript87039199384887039
jsc-3 (typed array)Javascript237409374023740
jsc-3 (untyped array)Javascript1899018164418990
js24 (typed array)Javascript2130896882130
js24 (untyped array)Javascript1530923841530
goGo140315681100798241240
rustc (debug)Rust390106844106208602011010
rustc (-O2)Rust410110204970861081380
scalaScala54302060885430
python3Python 39047040319290470
python3 (array)Python 310682087248106820
pypyPython 253401367645340
pypy (array)Python 258502045885850
mcsC#440459081380904721820
luaLua6564026409665640
luajitLua63001329646300
dartDart2120933922120

Write down your opinion (or pastie if you found a bug on these source, or if you want to add more language implementation) on the comment section ^^)b

Note #1Opal (0.6.8) and JRuby (both 1.7.18 and 9.0.0pre1) failed to run this benchmark (they exceed 300s runtime limit even when using -J-Xmx3000M -J-Djruby.compile.mode=FORCE flag).

Note #2: Yes, it's unfair to compare array of integer and array of double, life is unfair by design, get over it...