/mobile Handheld Friendly website

 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.0C++ g++ #7 10.6210.63100,496919  0% 0% 1% 100%
1.0Ada 2005 GNAT #5 10.8610.88158,3962167  0% 0% 1% 100%
1.0Ada 2005 GNAT #4 10.8610.88158,3522167  0% 0% 1% 100%
1.7Rust 17.9117.95180,456779  0% 0% 1% 100%
2.0Lisp SBCL #2 21.0321.07350,460649  1% 0% 0% 100%
2.0Haskell GHC #4 21.6321.66312,868612  0% 0% 1% 100%
2.2Java  #2 22.9622.99448,112603  0% 0% 1% 100%
2.2Java  #3 23.1023.14450,320584  0% 1% 1% 100%
2.2Fortran Intel #2 23.2023.22149,3681199  0% 0% 0% 100%
2.2Scala #4 23.2523.28450,892494  0% 0% 0% 100%
2.4Haskell GHC 25.4225.46314,880521  0% 1% 0% 100%
2.4C# Mono 25.5725.60180,164654  1% 1% 0% 100%
2.4F# Mono 25.8625.89184,920537  0% 0% 1% 100%
2.6Lisp SBCL 27.3127.36348,984612  0% 0% 1% 100%
3.4Clojure #2 36.5736.63632,772750  1% 1% 0% 100%
3.5C gcc 36.7036.72131,672706  0% 0% 1% 100%
3.5C++ g++ #2 36.8836.91197,760553  0% 1% 1% 100%
3.5Clojure 37.2537.30594,688657  1% 1% 0% 100%
3.5Clojure #6 37.4137.46547,896705  1% 1% 0% 100%
3.6Ada 2005 GNAT 38.0238.04198,176955  0% 0% 0% 100%
3.8Racket #2 39.8439.91397,088640  0% 0% 1% 100%
3.9Pascal Free Pascal 40.9340.95131,384769  1% 0% 0% 100%
4.1OCaml #5 43.8043.87232,168496  0% 0% 0% 100%
4.2OCaml #2 44.3744.47201,748784  0% 0% 0% 100%
4.4JavaScript V8 46.1846.25584,248467  0% 1% 0% 100%
4.5Fortran Intel 47.9948.02132,032826  3% 0% 0% 100%
4.6Racket 48.8348.91460,076495  0% 1% 1% 100%
4.8Dart 51.4951.54193,632503  0% 1% 1% 100%
4.9Hack #3 52.3152.39582,848480  1% 1% 0% 100%
5.0F# Mono #3 52.5752.64298,232565  0% 1% 1% 100%
5.4Erlang HiPE #2 57.3557.44647,288499  0% 0% 0% 100%
5.8C# Mono #2 61.8061.87616,256650  0% 0% 1% 100%
6.3Hack #2 66.5866.67385,236468  1% 1% 1% 100%
6.4Erlang HiPE 67.6667.77872,752441  0% 0% 0% 100%
6.6F# Mono #2 70.3070.38349,796515  0% 0% 0% 100%
7.4C gcc #5 78.2678.32219,160963  0% 0% 1% 100%
7.7Smalltalk VisualWorks 81.4081.49320,668722  0% 0% 0% 100%
9.3Ada 2005 GNAT #3 98.3898.45656,6401342  0% 0% 1% 100%
10Go 111.09111.22479,796516  1% 1% 1% 100%
11Hack 117.27117.39385,224506  0% 0% 0% 100%
12Go #5 124.25124.39516,0361000  0% 1% 1% 100%
12Go #4 124.65124.79572,472688  0% 1% 1% 100%
12Go #2 125.57125.71545,120694  0% 1% 1% 100%
17Ruby 184.49184.65825,196412  1% 1% 0% 100%
18Ruby #2 190.06190.21825,196413  1% 1% 0% 100%
18Ruby #3 194.55194.701,022,388439  1% 1% 0% 100%
21Ruby JRuby #3 223.32223.571,011,384439  0% 1% 0% 100%
43Lua #2 7 min7 min1,776,376446  0% 0% 0% 100%
45Python 3 #6 7 min8 min1,123,040626  0% 1% 1% 100%
55Perl 9 min9 min480,396448  0% 0% 0% 100%
60PHP #2 10 min10 min1,025,292472  0% 0% 0% 100%
67PHP 11 min11 min1,021,852504  0% 0% 0% 100%
C++ g++ #6 Make Error892
Perl #3 Failed706
PHP #3 Failed483
Racket #3 Bad Output877
Ruby JRuby Failed412
Scala #2 Failed641
"wrong" (different) algorithm / less comparable programs
0.3C gcc #2 3.423.4349,536594
0.7C gcc #9 7.257.27229,0281103
0.9C gcc #7 9.389.38149,140850
1.4OCaml 14.8214.85485,392563
2.0Scala 21.3721.40391,564549
2.1Haskell GHC #5 22.5822.60204,336611
4.7Go #6 49.7649.82453,532937
77PHP #4 821.05821.931,809,632945
 Lua #3 Timed Out  477

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

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