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.742.85103,700906  76% 76% 100% 93%
1.1Rust 12.063.1987,208827  93% 96% 99% 93%
1.8Ada 2005 GNAT #5 15.235.00109,8442167  71% 75% 70% 94%
1.8C++ g++ #6 15.895.05179,668892  73% 70% 97% 77%
1.8Ada 2005 GNAT #4 15.285.06105,6162167  71% 96% 65% 74%
2.3Fortran Intel #2 19.946.57125,0161199  67% 70% 71% 96%
3.6Clojure #2 32.8810.16531,228750  76% 90% 84% 76%
4.5Erlang HiPE #2 46.2612.88617,852499  99% 88% 88% 86%
4.6Java  #3 18.8013.20476,640584  38% 37% 32% 37%
4.7Java  #2 18.8013.38475,860603  17% 22% 21% 83%
4.8Haskell GHC #4 40.4113.66405,572612  67% 99% 67% 66%
5.1Scala #4 20.8314.40485,116494  46% 16% 39% 46%
5.1OCaml #2 38.4114.41102,344784  77% 33% 100% 60%
5.9Clojure 24.1316.72533,772657  30% 31% 51% 34%
5.9Go #8 57.8716.93139,136814  86% 85% 86% 86%
6.2Lisp SBCL #2 17.5217.54164,952649  1% 0% 100% 1%
7.1C# Mono 20.2420.24137,756654  98% 1% 2% 1%
7.3Haskell GHC 40.9320.77179,716521  33% 33% 100% 33%
7.7C# Mono #3 35.4722.09196,500723  44% 41% 36% 42%
8.3F# Mono 23.7223.72182,732537  100% 0% 1% 1%
8.3Dart 25.3623.76201,116503  12% 66% 5% 31%
8.5Go #2 90.9024.16176,316694  93% 94% 94% 96%
8.5Go #4 90.6724.20175,552688  93% 93% 96% 93%
8.7Go #5 96.7024.76175,2401000  98% 98% 98% 98%
9.1Lisp SBCL 26.0526.08171,136612  0% 1% 1% 100%
9.3Clojure #6 34.6926.42540,464705  48% 23% 15% 47%
9.6Racket #2 27.2327.26246,356640  1% 0% 0% 100%
11Ada 2005 GNAT #3 115.7031.83331,2641342  90% 91% 91% 93%
11C gcc #5 114.1032.04112,636963  93% 88% 92% 85%
12Erlang HiPE 33.0433.07534,884441  1% 1% 96% 4%
12Pascal Free Pascal 33.1933.2165,836769  1% 1% 1% 100%
12C gcc 34.1434.1666,096706  0% 1% 1% 100%
12OCaml #5 34.4234.46138,072496  0% 1% 1% 100%
13F# Mono #3 36.8036.81170,588565  26% 54% 1% 21%
13Racket 37.3637.41280,268495  0% 1% 100% 0%
14C++ g++ #2 38.5238.5599,080553  0% 100% 1% 2%
14Ada 2005 GNAT 41.2041.2299,420955  1% 0% 0% 100%
15C# Mono #2 42.9842.99320,644650  1% 99% 0% 1%
22F# Mono #2 61.6061.59252,036515  99% 1% 1% 1%
24Ruby #5 193.7567.48114,5881123  63% 63% 66% 96%
30Go #9 85.0484.98150,388548  37% 1% 63% 0%
30Go 85.1085.04150,552516  1% 0% 100% 1%
30Go #7 85.4885.44149,256567  9% 25% 1% 67%
44Python 3 7 min124.43465,940596  95% 94% 96% 93%
49Python 3 #6 8 min139.26688,512626  93% 96% 96% 94%
68Ruby #4 194.22194.32114,320402  1% 99% 0% 2%
71Fortran Intel 202.15202.38154,072826  98% 4% 5% 2%
81Ruby #2 230.87230.98202,420413  0% 1% 1% 100%
81Ruby #3 230.91231.04159,432439  1% 1% 55% 46%
82Ruby 233.65233.76202,472412  1% 67% 0% 34%
94Perl #3 14 min268.791,018,156706  90% 95% 73% 76%
110Ruby JRuby #3 11 min5 min842,440439  57% 66% 54% 52%
110Ruby JRuby #4 12 min5 min846,540402  69% 47% 48% 68%
123Ruby JRuby 14 min5 min840,788412  72% 54% 53% 70%
145Ruby JRuby #5 25 min6 min856,5281123  95% 94% 94% 95%
186PHP #2 8 min8 min549,952472  34% 66% 1% 1%
207PHP 9 min9 min546,228504  9% 78% 14% 1%
235PHP #3 11 min11 min1,255,012483  1% 23% 54% 24%
242Perl 11 min11 min330,928448  10% 34% 64% 13%
Racket #3 Bad Output877
Scala #2 Failed641
"wrong" (different) algorithm / less comparable programs
0.6C gcc #9 6.391.73114,3321103
1.0C gcc #2 2.962.9725,064594
1.1C gcc #7 11.263.25103,644850
1.5C++ g++ #7 13.234.2088,348919
3.4Go #6 35.559.77266,868861
3.6Go #3 37.7010.36342,724836
4.0Haskell GHC #5 28.4911.49114,856611
4.1Scala 17.4511.56389,904549
4.3OCaml 12.3412.36236,300563
36Python 3 #7 374.34102.86449,168613
57PHP #4 313.26162.10955,116945

 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