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
500,0001.571.581,052350  0% 0% 1% 100%
5,000,00015.5515.571,052350  0% 0% 1% 100%
50,000,000152.51152.621,052350  0% 0% 0% 100%

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

Read thread-ring benchmark to see what this program should do.

 notes

The OCaml native-code compiler, version 4.01.0

For this to work on 32bit we have to set ulimit -s 100

 thread-ring OCaml #2 program source code

(* The Computer Language Benchmarks Game
 * http://benchmarksgame.alioth.debian.org/
   contributed by Tomasz bla Fortuna *)

let size = 503
and n = int_of_string Sys.argv.(1)

type channel = { m : Mutex.t; d : int ref }
let channel () =
  let mx = Mutex.create () in Mutex.lock mx;
  { m = mx; d = ref 0}

let rec spawn id i o loop () =
  let rec thread () =
    Mutex.lock i.m;
    if !(i.d) = n then (
      print_int (size-id+1); print_newline (); exit 0;
    );
    o.d := !(i.d) + 1;  (* Forward token *)
    Mutex.unlock o.m;
    thread ()
  in
  if id > 1 then (
    let new_o = if id = 2 then loop else channel () in
    let f = spawn (id-1) o new_o loop in
    ignore (Thread.create f ())
  );
  thread ()

let _ =
  let loop, o = channel (), channel () in
  Mutex.unlock loop.m;
  Thread.join (Thread.create (spawn size loop o loop) ())

 make, command-line, and program output logs

Fri, 13 Sep 2013 17:18:13 GMT

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

COMMAND LINE:
./threadring.ocaml-2.ocaml_run 50000000

PROGRAM OUTPUT:
292

Revised BSD license

  Home   Conclusions   License   Play