binary-trees benchmark N=20

Each chart bar shows how many times slower, one ↓ binary-trees program was, compared to the fastest program.

These are not the only programs that could be written. These are not the only compilers and interpreters. These are not the only programming languages.

Column × shows how many times more each program used compared to the benchmark program that used least.

    sort sortsort
  ×   Program Source Code CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
1.0Java  #6 7.387.39414,024583  1% 1% 1% 100%
1.3C gcc #3 9.269.28150,364906  0% 0% 1% 100%
1.4Java  #5 9.979.99530,224926  0% 1% 1% 100%
1.4Ada 2005 GNAT #5 10.6710.70160,6682167  1% 1% 0% 100%
1.4Ada 2005 GNAT #4 10.6810.71160,6762167  1% 1% 0% 100%
1.7C++ g++ #6 12.8812.90297,932892  1% 0% 0% 100%
1.8Rust 13.6213.64119,436791  1% 0% 1% 100%
2.3Fortran Intel #2 16.9116.92149,3801199  1% 1% 1% 100%
2.3Java  #2 17.1617.18519,692603  1% 1% 1% 100%
2.3Java  #3 17.2617.28518,964584  1% 1% 0% 100%
2.3Go #6 17.2917.36221,460752  0% 0% 1% 100%
2.4Scala #4 17.4717.50518,364494  1% 0% 0% 100%
3.0Haskell GHC #4 21.9722.01311,828612  0% 1% 1% 100%
3.3Clojure 24.4824.52617,100657  0% 1% 1% 100%
3.3Haskell GHC 24.5724.62314,852521  0% 1% 1% 100%
3.4Clojure #6 24.8624.90628,484705  1% 1% 0% 100%
3.4Lisp SBCL #2 24.8724.92292,580649  0% 1% 1% 100%
3.4C# Mono 25.0225.06161,736654  0% 1% 1% 100%
3.5F# Mono 25.9225.96163,572537  1% 0% 0% 100%
3.5Clojure #2 26.1526.19623,872750  0% 1% 1% 100%
4.4Dart 32.2732.31322,768503  0% 0% 1% 100%
4.4Lisp SBCL 32.3532.40311,068612  0% 1% 1% 100%
4.7Hack #3 34.9034.94397,428480  0% 0% 1% 100%
5.0C gcc 36.6236.65132,456706  1% 0% 1% 100%
5.1C++ g++ #2 37.9437.98199,212553  1% 1% 0% 100%
5.3Erlang HiPE 39.0839.141,032,524441  1% 1% 1% 100%
5.3Ada 2005 GNAT 39.1639.20200,008955  2% 1% 1% 100%
5.6Racket #2 41.0441.10385,968640  0% 1% 0% 100%
5.6Pascal Free Pascal 41.6141.65131,376769  1% 1% 1% 100%
5.9OCaml #2 43.3243.39202,856784  2% 0% 0% 100%
6.1OCaml #5 44.8944.95274,680496  0% 1% 0% 100%
6.6Racket 48.7448.81461,692495  0% 1% 1% 100%
6.6JavaScript V8 48.9249.00937,048467  0% 1% 0% 100%
6.8Erlang HiPE #2 50.4450.52512,984499  1% 1% 0% 100%
6.9Fortran Intel 50.8050.84132,032826  1% 1% 0% 100%
7.0F# Mono #3 51.7651.84229,448565  0% 1% 1% 100%
7.8Go #8 57.2757.35254,248814  0% 1% 1% 100%
7.9C# Mono #2 58.6158.70457,044650  0% 1% 1% 100%
9.5F# Mono #2 70.4770.58281,572515  0% 1% 1% 100%
11C gcc #5 79.6579.71221,888963  1% 1% 1% 100%
11Smalltalk VisualWorks 81.8581.97331,556722  0% 1% 1% 100%
13Ada 2005 GNAT #3 97.4297.49660,7761342  1% 1% 0% 100%
15Hack #2 107.58107.67459,516468  2% 8% 6% 100%
16Hack 121.13121.22463,512506  0% 1% 1% 100%
22Go #5 160.98161.13292,2361000  0% 1% 1% 100%
22Ruby #4 165.21165.40240,392402  0% 1% 1% 100%
24Ruby #5 176.92177.11240,6801123  1% 1% 1% 100%
25Go #4 183.05183.23328,844688  0% 1% 1% 100%
26Go #2 193.14193.31327,128694  0% 1% 1% 100%
27Ruby #3 201.01201.20298,000439  1% 1% 0% 100%
27Ruby JRuby #3 201.82202.061,017,040439  1% 1% 1% 100%
28Ruby 204.15204.37388,384412  0% 1% 1% 100%
28Ruby #2 207.57207.76387,892413  0% 1% 1% 100%
28Go 210.40210.57276,728516  0% 0% 1% 100%
29Go #9 216.34216.51259,708548  0% 1% 1% 100%
31Go #7 231.54231.72276,008567  0% 1% 1% 100%
33Scala #5 243.64243.81494,144688  1% 1% 1% 100%
52Ruby JRuby 6 min6 min1,017,692412  0% 1% 1% 100%
57Lua #2 6 min6 min1,672,244446  0% 1% 1% 100%
60Python 3 7 min7 min836,008596  1% 1% 0% 100%
67Ruby JRuby #4 8 min8 min912,756402  0% 1% 1% 100%
83PHP #2 10 min10 min1,021,788472  1% 1% 0% 100%
83Perl 10 min10 min546,676448  0% 1% 1% 100%
90PHP 11 min11 min1,021,916504  1% 1% 0% 100%
172Ruby JRuby #5 21 min21 min938,2361123  0% 1% 1% 100%
C# Mono #3 Failed723
Go #3 Bad Output830
Perl #3 Failed706
PHP #3 Failed483
Racket #3 Bad Output877
Scala #2 Failed641
"wrong" (different) algorithm / less comparable programs
0.5C gcc #2 3.583.5950,424594
1.0C gcc #9 7.187.19229,3681103
1.2C gcc #7 9.159.16150,500850
1.4C++ g++ #7 10.1710.19102,052919
2.1OCaml 15.3615.38476,712563
2.2Scala 16.1516.17420,848549
3.0Haskell GHC #5 22.2222.24204,300611
48Python 3 #7 353.59353.98836,232613
48PHP #4 356.91357.301,826,308945
146Lua #3 419.861.003,663,800477

 binary-trees benchmark : Allocate and deallocate many many binary trees

You can write your own program for this task and contribute to the benchmarks game by following these general instructions.

More specifically:

diff program output N = 10 with this 1KB output file to check your program is correct before contributing.

We are trying to show the performance of various programming language implementations - so we ask that contributed programs not only give the correct result, but also use the same algorithm to calculate that result.

Each program should

Note: this is an adaptation of a benchmark for testing GC so we are interested in the whole tree being allocated before any nodes are GC'd - which probably excludes lazy evaluation.

Note: the left subtrees are heads of the right subtrees, keeping a depth counter in the accessors to avoid duplication is cheating!

Note: the tree should have tree-nodes all the way down, replacing the bottom nodes by some other value is not acceptable; and the bottom nodes should be at depth 0.

Note: these programs are being measured with the default initial heap size - the measurements may be very different with a larger initial heap size or GC tuning.

Please don't implement your own custom memory pool or free list.


The binary-trees benchmark is a simplistic adaptation of Hans Boehm's GCBench, which in turn was adapted from a benchmark by John Ellis and Pete Kovac.

Thanks to Christophe Troestler and Einar Karttunen for help with this benchmark.

Revised BSD license

  Home   Conclusions   License   Play