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.399.4099,424906  0% 72% 34% 100%
1.2C++ g++ #6 10.9210.94148,508892  1% 1% 0% 100%
1.2Ada 2005 GNAT #4 11.1511.17105,6762167  0% 1% 1% 100%
1.2Ada 2005 GNAT #5 11.1711.20105,6842167  0% 1% 1% 100%
1.5Rust 14.4814.50130,452788  1% 1% 1% 100%
1.7Java  #3 16.2816.30511,448584  1% 1% 0% 100%
1.8Java  #2 16.5616.59510,068603  1% 1% 1% 100%
1.9Scala #4 17.4617.49506,212494  1% 1% 0% 100%
1.9Haskell GHC #4 18.2318.25173,344612  0% 1% 1% 100%
2.0Lisp SBCL #2 18.7018.73193,676649  1% 0% 0% 100%
2.0Haskell GHC 18.9118.94166,212521  0% 0% 0% 100%
2.2C# Mono 20.3220.35121,732654  1% 0% 0% 100%
2.3Clojure 21.7321.76512,756657  0% 1% 1% 100%
2.4Clojure #2 22.5822.62511,792750  1% 1% 0% 100%
2.5Fortran Intel #2 23.7723.7999,6161199  0% 0% 0% 100%
2.5F# Mono 23.9223.95171,856537  1% 1% 0% 100%
2.6Dart 24.5024.53212,200503  1% 1% 0% 100%
2.9Racket #2 27.1427.18218,080640  1% 1% 1% 100%
2.9Lisp SBCL 27.2427.27193,672612  1% 0% 0% 100%
3.3Clojure #6 30.8530.90529,700705  1% 1% 1% 100%
3.5Pascal Free Pascal 33.2633.2865,836769  0% 1% 0% 100%
3.6JavaScript V8 33.3633.41448,540467  1% 1% 1% 100%
3.6C gcc 34.1634.1866,096706  0% 0% 1% 100%
3.7OCaml #2 35.0035.07101,028784  0% 0% 0% 100%
3.8OCaml #5 35.8935.93115,712496  0% 0% 0% 100%
3.9F# Mono #3 36.8836.92171,124565  1% 1% 0% 100%
4.0Racket 37.3837.43281,180495  0% 1% 1% 100%
4.1C++ g++ #2 38.8538.8799,080553  0% 0% 1% 100%
4.3Ada 2005 GNAT 40.6540.6899,416955  1% 0% 0% 100%
4.6C# Mono #2 42.7942.84290,004650  1% 1% 0% 100%
5.1Erlang HiPE #2 47.5747.63338,644499  0% 0% 0% 100%
5.4Erlang HiPE 50.4950.55443,172441  0% 0% 0% 100%
5.7Go #8 54.0054.05134,696814  0% 1% 0% 100%
6.6F# Mono #2 61.9261.99283,860515  1% 0% 0% 100%
7.0Smalltalk VisualWorks 65.6065.67316,312722  0% 0% 0% 100%
8.1C gcc #5 76.1676.20109,632963  1% 1% 0% 100%
9.4Go #7 88.6488.71170,400567  1% 1% 0% 100%
9.6Go 89.8289.91170,752516  1% 1% 0% 100%
9.6Go #4 90.4890.57199,244688  1% 0% 0% 100%
9.6Go #2 90.5790.65199,132694  1% 1% 1% 100%
9.7Go #5 91.1391.23196,0401000  1% 1% 0% 100%
12Ada 2005 GNAT #3 114.60114.66329,0601342  0% 1% 1% 100%
18Ruby JRuby #3 168.68168.87899,264439  1% 1% 1% 100%
18Fortran Intel 173.18173.35153,800826  0% 0% 0% 100%
24Ruby #2 222.74222.85557,644413  0% 1% 1% 100%
24Ruby #3 226.44226.55409,360439  0% 1% 1% 100%
24Ruby 227.06227.16400,436412  0% 0% 1% 100%
27Ruby JRuby 253.43253.68895,044412  0% 1% 1% 100%
48Lua #2 7 min7 min1,033,624446  0% 14% 4% 100%
54Python 3 #6 8 min8 min688,448626  1% 1% 1% 100%
58PHP #2 9 min9 min546,272472  0% 0% 0% 100%
64Perl 10 min10 min289,324448  0% 0% 0% 100%
66PHP 10 min10 min546,248504  0% 0% 0% 100%
100PHP #3 15 min15 min1,260,280483  1% 1% 4% 100%
Perl #3 Failed706
Racket #3 Bad Output877
Scala #2 Failed641
"wrong" (different) algorithm / less comparable programs
0.3C gcc #2 2.952.9625,064594
0.7C gcc #9 6.226.23114,3361103
1.0C gcc #7 9.459.4699,448850
1.1C++ g++ #7 10.4210.4366,996919
1.4OCaml 12.7412.77235,724563
1.7Scala 16.1416.16379,632549
2.1Haskell GHC #5 20.1920.2188,332611
 Go #3 Failed  836
3.6Go #6 33.4433.48273,412937
51Lua #3 477.10477.692,963,916477
58PHP #4 541.62542.15957,228945
missing benchmark programs
C CINT No program

 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