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.4Rust 15.384.06130,456788  96% 99% 93% 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.8Fortran Intel #2 23.997.93116,9801199  68% 68% 98% 69%
3.6Clojure #2 32.4310.17517,208750  77% 78% 93% 75%
4.5Java  #3 17.7512.78471,136584  77% 15% 15% 34%
4.6Java  #2 18.0213.13471,008603  62% 21% 22% 34%
4.8Haskell GHC #4 40.3313.56398,172612  66% 67% 100% 66%
4.9Scala #4 18.5813.84480,552494  71% 13% 13% 39%
5.7Go #8 60.5116.24140,220814  92% 93% 94% 94%
5.7OCaml #2 40.1416.27101,028784  36% 95% 49% 69%
5.8Clojure 22.9916.53517,204657  29% 41% 34% 38%
5.9Erlang HiPE #2 52.6316.82646,636499  89% 75% 70% 81%
6.6Lisp SBCL #2 18.6518.68193,672649  1% 1% 1% 100%
7.2Haskell GHC 40.0320.51169,524521  32% 100% 33% 32%
7.3C# Mono 20.7420.74134,020654  0% 39% 1% 61%
8.5Dart 24.4924.33212,060503  1% 1% 1% 100%
8.6F# Mono 24.4624.46173,416537  0% 32% 1% 68%
9.2Clojure #6 32.9326.12523,000705  24% 58% 18% 27%
9.6Lisp SBCL 27.2227.25193,676612  1% 0% 100% 1%
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%
12Pascal Free Pascal 33.1933.2165,836769  1% 1% 1% 100%
12Go #5 132.7633.83178,4041000  99% 99% 99% 99%
12Go #4 130.8133.93197,388688  96% 96% 96% 98%
12Go #2 132.2334.08195,384694  99% 97% 97% 97%
12C gcc 34.1434.1666,096706  0% 1% 1% 100%
13OCaml #5 35.6835.73115,716496  0% 0% 0% 100%
13F# Mono #3 37.3437.35173,072565  74% 8% 4% 16%
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%
16C# Mono #2 44.3744.39293,988650  16% 76% 4% 6%
18Erlang HiPE 50.9250.98427,992441  2% 1% 97% 2%
22F# Mono #2 62.8062.81262,412515  56% 24% 0% 21%
26Ruby #5 218.7175.02131,0281123  65% 68% 64% 96%
31Go #7 88.6588.62169,904567  29% 1% 40% 33%
32Go 89.9289.87172,808516  1% 1% 34% 67%
38Ruby JRuby #4 174.11107.69891,688402  47% 53% 40% 24%
39Ruby JRuby #3 178.97111.92900,496439  31% 66% 41% 23%
47Ruby JRuby 261.64133.49891,920412  37% 89% 35% 36%
49Python 3 #6 8 min139.26688,512626  93% 96% 96% 94%
62Fortran Intel 177.99178.17153,820826  0% 0% 0% 100%
76Ruby JRuby #5 13 min216.68839,3601123  94% 95% 95% 95%
76Ruby #4 216.82216.91301,032402  0% 1% 1% 100%
77Ruby #3 220.52220.62343,968439  0% 1% 1% 100%
79Ruby 225.45225.54485,228412  0% 1% 100% 0%
79Ruby #2 226.38226.47370,008413  0% 1% 1% 100%
91Perl #3 14 min258.43912,720706  94% 69% 100% 72%
192PHP #2 9 min9 min546,272472  72% 24% 5% 4%
220PHP 10 min10 min547,708504  0% 97% 3% 0%
234Perl 11 min11 min289,788448  89% 10% 3% 7%
323PHP #3 15 min15 min1,256,324483  0% 0% 0% 100%
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.6Go #3 36.9210.36434,704836
4.2Haskell GHC #5 29.1411.85106,400611
4.3Scala 17.5712.27359,384549
4.4OCaml 12.6312.65235,720563
6.2Go #6 39.1417.55281,436937
121PHP #4 673.93344.32957,240945

 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