/mobile Handheld Friendly website

 performance measurements

Each table row shows performance measurements for this OCaml program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
120.040.05?563  20% 0% 0% 80%
160.540.5441,416563  8% 30% 100% 21%
2012.6312.65235,720563  1% 0% 0% 100%

Read the ↓ make, command line, and program output logs to see how this program was run.

Read binary-trees benchmark to see what this program should do.

 notes

The OCaml native-code compiler, version 4.01.0

NOT ACCEPTED: We accept the default GC settings.

 binary-trees OCaml program source code

(* The Computer Language Benchmarks Game
 * http://benchmarksgame.alioth.debian.org/
 *
 * Contributed by Troestler Christophe
 * Modified by Fabrice Le Fessant for
 *  - tree type more compact
 *  - better GC parameters
 *  - loops replaced by recursive functions
 *)

type 'a tree = Leaf of 'a | Node of 'a tree * 'a * 'a tree

let rec make d i =
  if d = 0 then Leaf i
  else
    let l = make (d-1) (2*i - 1) in
    let r = make (d-1) (2*i) in
      Node(l, i, r)

let rec check = function Leaf i -> i | Node(l, i, r) ->
  let i = i + check l in
    i - check r

let min_depth = 4
let n = if Array.length Sys.argv <> 2 then 0 else int_of_string Sys.argv.(1)
let max_depth = max (min_depth + 2) n
let stretch_depth = max_depth + 1

let _ =
  let gc = Gc.get () in
    gc.Gc.max_overhead <- 1000000;
    gc.Gc.space_overhead <- 500;
    gc.Gc.major_heap_increment <- 10_000_000;
    gc.Gc.minor_heap_size <- 10_000_000;
    Gc.set gc

let () =
  let c = check (make stretch_depth 0) in
  Printf.printf "stretch tree of depth %i\t check: %i\n" stretch_depth c

let long_lived_tree = make max_depth 0


let rec iter i niter c d =
  if i <= niter then
    let c = c + check(make d i) in
    let c = c + check(make d (-i)) in
    iter (i+1) niter c d
  else
    Printf.printf "%i\t trees of depth %i\t check: %i\n" (2 * niter) d c


let rec loop_depths d =
  let niter = 1 lsl (max_depth - d + min_depth) in
    iter 1 niter 0 d;
    if d < max_depth then
      loop_depths (d+2)

let () =
  flush stdout;
  loop_depths min_depth;
  Printf.printf "long lived tree of depth %i\t check: %i\n"
    max_depth (check long_lived_tree)

 make, command-line, and program output logs

Thu, 12 Sep 2013 18:11:41 GMT

MAKE:
mv binarytrees.ocaml binarytrees.ml
/usr/local/bin/ocamlopt -noassert -unsafe -nodynlink -inline 100 unix.cmxa binarytrees.ml -o binarytrees.ocaml_run
rm binarytrees.ml
0.89s to complete and log all make actions

COMMAND LINE:
./binarytrees.ocaml_run 20

PROGRAM OUTPUT:
stretch tree of depth 21	 check: -1
2097152	 trees of depth 4	 check: -2097152
524288	 trees of depth 6	 check: -524288
131072	 trees of depth 8	 check: -131072
32768	 trees of depth 10	 check: -32768
8192	 trees of depth 12	 check: -8192
2048	 trees of depth 14	 check: -2048
512	 trees of depth 16	 check: -512
128	 trees of depth 18	 check: -128
32	 trees of depth 20	 check: -32
long lived tree of depth 20	 check: -1

Revised BSD license

  Home   Conclusions   License   Play