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 gcc #3 9.269.28150,364906  0% 0% 1% 100%
1.1Java  #5 9.979.99530,224926  0% 1% 1% 100%
1.2Ada 2005 GNAT #5 10.6710.70160,6682167  1% 1% 0% 100%
1.2Ada 2005 GNAT #4 10.6810.71160,6762167  1% 1% 0% 100%
1.4C++ g++ #6 12.8812.90297,932892  1% 0% 0% 100%
1.6Rust 14.5714.59119,424791  1% 1% 0% 100%
1.8Fortran Intel #2 16.9116.92149,3801199  1% 1% 1% 100%
1.9Java  #2 17.1617.18519,692603  1% 1% 1% 100%
1.9Java  #3 17.2617.28518,964584  1% 1% 0% 100%
1.9Scala #4 17.4717.50518,364494  1% 0% 0% 100%
2.4Haskell GHC #4 21.9722.01311,828612  0% 1% 1% 100%
2.6C# Mono 24.0724.11164,212654  1% 1% 1% 100%
2.6Clojure 24.4824.52617,100657  0% 1% 1% 100%
2.7Haskell GHC 24.5724.62314,852521  0% 1% 1% 100%
2.7Clojure #6 24.8624.90628,484705  1% 1% 0% 100%
2.7Lisp SBCL #2 24.8724.92292,580649  0% 1% 1% 100%
2.7F# Mono 25.1125.16162,216537  1% 1% 0% 100%
2.8Clojure #2 26.1526.19623,872750  0% 1% 1% 100%
3.4Dart 31.9031.94337,716503  0% 1% 1% 100%
3.5Lisp SBCL 32.3532.40311,068612  0% 1% 1% 100%
4.0C gcc 36.6236.65132,456706  1% 0% 1% 100%
4.0Hack #3 37.0737.11638,008480  1% 0% 1% 100%
4.0Erlang HiPE 37.2537.311,057,544441  0% 1% 1% 100%
4.1C++ g++ #2 37.9437.98199,212553  1% 1% 0% 100%
4.2Ada 2005 GNAT 39.1639.20200,008955  2% 1% 1% 100%
4.4Racket #2 40.5140.57413,456640  1% 0% 1% 100%
4.5Pascal Free Pascal 41.6141.65131,376769  1% 1% 1% 100%
4.7OCaml #2 43.3243.39202,856784  2% 0% 0% 100%
4.8OCaml #5 44.8944.95274,680496  0% 1% 0% 100%
5.2Racket 48.4748.56464,724495  1% 1% 1% 100%
5.3Erlang HiPE #2 48.9649.03512,732499  0% 0% 1% 100%
5.5F# Mono #3 50.5950.67258,648565  1% 1% 0% 100%
5.5Fortran Intel 50.8050.84132,032826  1% 1% 0% 100%
5.8JavaScript V8 53.5753.65912,160467  1% 1% 0% 100%
6.0Go #8 55.2855.35264,284814  0% 1% 1% 100%
6.1C# Mono #2 56.4956.58454,552650  1% 1% 0% 100%
7.4F# Mono #2 68.1068.20282,392515  1% 1% 0% 100%
8.6C gcc #5 79.6579.71221,888963  1% 1% 1% 100%
8.8Smalltalk VisualWorks 81.0481.16329,960722  0% 0% 0% 100%
9.6Go #4 88.9489.04338,388688  1% 1% 1% 100%
9.6Go #2 89.0189.12339,308694  0% 1% 0% 100%
9.8Go 90.9591.06288,536516  0% 1% 1% 100%
10Go #9 92.1392.24290,548548  0% 0% 1% 100%
10Go #7 92.6892.79290,256567  1% 1% 1% 100%
10Go #5 94.2994.41335,3841000  1% 1% 1% 100%
11Ada 2005 GNAT #3 97.4297.49660,7761342  1% 1% 0% 100%
13Hack #2 117.86117.97771,420468  1% 1% 1% 100%
13Hack 123.84124.17769,240506  1% 0% 0% 100%
18Ruby #4 165.21165.40240,392402  0% 1% 1% 100%
19Ruby #5 176.92177.11240,6801123  1% 1% 1% 100%
22Ruby #3 201.01201.20298,000439  1% 1% 0% 100%
22Ruby JRuby #3 201.82202.061,017,040439  1% 1% 1% 100%
22Ruby 204.15204.37388,384412  0% 1% 1% 100%
22Ruby #2 207.57207.76387,892413  0% 1% 1% 100%
41Ruby JRuby 6 min6 min1,017,692412  0% 1% 1% 100%
45Lua #2 6 min6 min1,672,244446  0% 1% 1% 100%
48Python 3 7 min7 min836,008596  1% 1% 0% 100%
53Ruby JRuby #4 8 min8 min912,756402  0% 1% 1% 100%
66PHP #2 10 min10 min1,021,788472  1% 1% 0% 100%
66Perl 10 min10 min546,676448  0% 1% 1% 100%
72PHP 11 min11 min1,021,916504  1% 1% 0% 100%
137Ruby JRuby #5 21 min21 min938,2361123  0% 1% 1% 100%
C# Mono #3 Failed723
Perl #3 Failed706
PHP #3 Failed483
Racket #3 Bad Output877
Scala #2 Failed641
"wrong" (different) algorithm / less comparable programs
0.4C gcc #2 3.583.5950,424594
0.8C gcc #9 7.187.19229,3681103
1.0C gcc #7 9.159.16150,500850
1.1C++ g++ #7 10.1710.19102,052919
1.7OCaml 15.3615.38476,712563
1.7Scala 16.1516.17420,848549
2.4Haskell GHC #5 22.2222.24204,300611
3.9Go #3 36.0536.11650,604836
4.0Go #6 37.4937.55509,756861
38Python 3 #7 353.59353.98836,232613
39PHP #4 356.91357.301,826,308945
116Lua #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