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 10.183.26160,856906  64% 76% 75% 99%
1.1Java  #4 11.543.43445,500919  82% 83% 93% 81%
1.2Rust 14.974.01121,428791  92% 94% 94% 96%
1.7Ada 2005 GNAT #4 18.005.46178,5082167  93% 76% 77% 88%
1.7Ada 2005 GNAT #5 17.805.49179,0802167  72% 91% 87% 78%
1.8Fortran Intel #2 19.176.02184,4201199  77% 73% 70% 100%
2.5C++ g++ #6 27.948.28359,596892  90% 76% 91% 83%
4.1Java  #3 19.2913.34517,584584  42% 32% 27% 46%
4.1Java  #2 18.8913.40518,596603  22% 57% 41% 23%
4.2Scala #4 19.5313.65518,700494  16% 57% 38% 34%
4.3Clojure #2 47.0413.93609,300750  83% 87% 89% 81%
5.8Go #8 64.1918.90265,788814  86% 86% 85% 85%
5.8Clojure 30.3119.01611,544657  29% 26% 49% 57%
5.9Erlang HiPE #2 68.8219.05965,168499  93% 93% 87% 89%
5.9Clojure #6 27.1119.19608,212705  54% 49% 22% 18%
6.4Haskell GHC #4 66.7220.72830,536612  75% 80% 94% 75%
6.4C gcc #5 79.5420.88221,316963  99% 90% 96% 97%
7.5OCaml #2 70.9124.46202,980784  72% 75% 58% 86%
7.7Lisp SBCL #2 24.9124.95294,672649  0% 100% 1% 0%
7.7C# Mono 25.1325.12135,868654  19% 1% 24% 58%
7.8F# Mono 25.4025.38134,468537  1% 25% 1% 75%
8.2Haskell GHC 57.4026.83359,548521  73% 65% 38% 39%
8.6Go #2 103.8528.13337,948694  92% 93% 92% 94%
8.8Go #4 105.2928.49337,552688  92% 94% 92% 92%
9.0Go #5 114.0329.26337,3961000  98% 98% 97% 98%
9.1Dart 32.4629.64331,840503  7% 54% 43% 7%
9.2Ada 2005 GNAT #3 100.9629.96658,8281342  84% 85% 84% 84%
9.3C# Mono #3 45.1430.36295,988723  41% 34% 38% 38%
9.4Erlang #2 111.3830.73827,372499  93% 90% 91% 90%
10Lisp SBCL 32.4032.45311,072612  100% 0% 1% 1%
11C gcc 36.7636.79132,456706  100% 0% 0% 1%
11Hack #3 37.0337.07596,756480  1% 0% 0% 100%
12C++ g++ #2 37.9638.00199,300553  69% 32% 0% 1%
12Erlang HiPE 38.2038.251,058,568441  97% 4% 1% 0%
12Ada 2005 GNAT 39.1439.17200,056955  1% 100% 0% 0%
12Racket #2 40.4640.51412,592640  1% 0% 100% 1%
13Pascal Free Pascal 40.9140.96131,380769  0% 1% 0% 100%
14OCaml #5 44.5544.61274,692496  0% 1% 1% 100%
15Racket 48.6448.71333,344495  1% 0% 100% 0%
15F# Mono #3 50.1750.16349,788565  51% 1% 1% 49%
17C# Mono #2 56.2256.21607,056650  0% 1% 100% 0%
19Ruby #5 176.2260.91240,6761123  95% 65% 63% 69%
20Fortran Intel 66.6166.65132,308826  31% 57% 0% 13%
23F# Mono #2 75.7775.74232,836515  3% 53% 45% 1%
28Erlang 89.8189.89825,280441  41% 34% 2% 27%
28Go 91.0091.02286,328516  1% 11% 1% 89%
28Go #9 91.9791.96287,616548  17% 83% 0% 2%
29Go #7 93.1493.15288,796567  0% 0% 100% 1%
30Ruby JRuby #4 157.7997.791,168,552402  52% 25% 25% 68%
31Ruby JRuby #3 160.76101.781,191,532439  28% 47% 52% 33%
33Hack #2 107.48107.56727,764468  100% 0% 0% 0%
35Hack 112.91112.98727,696506  99% 1% 1% 1%
40Python 3 8 min129.60835,824596  93% 94% 98% 93%
52Ruby #4 168.26168.44240,348402  0% 1% 0% 100%
61Ruby #2 197.50197.72388,004413  45% 41% 5% 11%
62Ruby #3 200.33200.56291,636439  36% 1% 38% 27%
62Ruby 201.88202.06388,196412  1% 1% 100% 0%
69Ruby JRuby #5 14 min226.171,205,2961123  95% 96% 95% 95%
73Perl #3 13 min238.081,706,872706  94% 72% 96% 77%
186PHP #2 10 min10 min1,021,744472  38% 22% 42% 0%
196Perl 10 min10 min546,828448  6% 95% 0% 1%
205PHP 11 min11 min1,031,360504  10% 0% 91% 1%
228PHP #3 12 min12 min2,379,344483  14% 21% 0% 66%
Racket #3 Bad Output877
Ruby JRuby Failed412
Scala #2 Failed641
"wrong" (different) algorithm / less comparable programs
0.9C gcc #9 9.562.92229,2961103
1.1C gcc #2 3.583.5950,460594
1.3C gcc #7 13.764.22156,760850
1.5C++ g++ #7 15.264.74134,308919
3.4Scala 17.5211.02412,472549
3.6Go #6 44.6111.84506,632861
3.7Go #3 43.0011.91647,528836
4.2Haskell GHC #5 37.0413.72190,724611
4.7OCaml 15.2815.30476,828563
29Python 3 #7 363.4595.99836,208613
67PHP #4 420.11218.831,834,480945

 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