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?784  17% 0% 0% 100%
161.681.7096,932784  1% 0% 1% 100%
2044.3744.47201,748784  0% 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

 binary-trees OCaml #2 program source code

(* The Computer Language Benchmarks Game
 * http://benchmarksgame.alioth.debian.org/
 *
 * Contributed by Troestler Christophe
 * Rough parallelization by Mauricio Fernandez
 *)

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

let rec make i d =
(* if d = 0 then Empty *)
  if d = 0 then Node(Empty, i, Empty)
  else let i2 = 2 * i and d = d - 1 in Node(make (i2 - 1) d, i, make i2 d)

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

let min_depth = 4
let max_depth = (let n = try int_of_string(Array.get Sys.argv 1) with _ -> 10 in
                 max (min_depth + 2) n)
let stretch_depth = max_depth + 1

let () =
  (* Gc.set { (Gc.get()) with Gc.minor_heap_size = 1024 * 1024; max_overhead = -1; }; *)
  let c = check (make 0 stretch_depth) in
  Printf.printf "stretch tree of depth %i\t check: %i\n" stretch_depth c

let long_lived_tree = make 0 max_depth

let rec loop_depths d =
  let worker d =
    let niter = 1 lsl (max_depth - d + min_depth) and c = ref 0 in
    for i = 1 to niter do c := !c + check(make i d) + check(make (-i) d) done;
    (niter, !c) in
  let workers = Array.init ((max_depth - d) / 2 + 1)
                  (fun i -> let d = d + i * 2 in (d, invoke worker d))
  in Array.iter
       (fun (d, w) ->
          let niter, c = w () in
          Printf.printf "%i\t trees of depth %i\t check: %i\n" (2 * niter) d c)
       workers

(* function originally due to Jon D. Harrop *)
and invoke (f : 'a -> 'b) x : unit -> 'b =
  let input, output = Unix.pipe() in
  match Unix.fork() with
  | -1 -> Unix.close input; Unix.close output; (let v = f x in fun () -> v)
  | 0 ->
      Unix.close input;
      let output = Unix.out_channel_of_descr output in
      Marshal.to_channel output (try `Res(f x) with e -> `Exn e) [];
      close_out output;
      exit 0
  | pid ->
      Unix.close output;
      let input = Unix.in_channel_of_descr input in
      fun () ->
        let v = Marshal.from_channel input in
        ignore (Unix.waitpid [] pid);
        close_in input;
        match v with
        | `Res x -> x
        | `Exn e -> raise e

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

Fri, 13 Sep 2013 03:38:23 GMT

MAKE:
mv binarytrees.ocaml-2.ocaml binarytrees.ocaml-2.ml
/usr/local/bin/ocamlopt -noassert -unsafe -fno-PIC -nodynlink -inline 100 unix.cmxa binarytrees.ocaml-2.ml -o binarytrees.ocaml-2.ocaml_run
File "binarytrees.ocaml-2.ml", line 1:
Warning 24: bad source file name: "Binarytrees.ocaml-2" is not a valid module name.
rm binarytrees.ocaml-2.ml
0.22s to complete and log all make actions

COMMAND LINE:
./binarytrees.ocaml-2.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