bench.ml 1.39 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
open Printf

let gen = "split.ml"
let xml = "split"
let cduce = [ "split0.cd"; "split1.cd"; "split2.cd" ]
let xslt = [ "split1.xsl"; "split2.xsl" ]
let xduce = [ "split1.q"; "split2.q" ]

let sp = sprintf
let langs = 
  [
    "CDuce", cduce,
    (fun script xml -> 
       sp "../cduce --quiet %s --arg %s" script xml);

    "XDuce", xduce,
    (fun script xml -> 
       sp "/home/frisch/xduce-0.4.0/xduce.opt %s %s" script xml);

    "XSLT", xslt,
    (fun script xml -> 
       sp "xsltproc --noout %s %s" script xml);
  ]
  

let pr = printf
let rep = 1
let time s =
  let s = "/usr/bin/time --format=\"%e,%U\\n\" " ^ s ^ " 2>&1" in
  flush stdout;
  for i = 1 to rep do
    let ic = Unix.open_process_in s in
    let t = input_line ic in
    ignore (Unix.close_process_in ic);
    pr "%s " t;
    flush stdout;
  done;
  pr "\n"

let args = [ 10 ; 50; 100; (* 500; 1000; 5000 *) ]

let run s = 
  flush stdout; 
  ignore (Sys.command s)

let () =
  List.iter
    (fun s ->
       let fn = sp "%s.%i.xml" xml s in
       run (sp "ocaml %s %i > %s" gen s fn);
       let ic = open_in fn in
       let size = in_channel_length ic in
       close_in ic;
       pr "XML size = %i\n" size;
       List.iter
	 (fun (lang, scripts, cmd) ->
	    List.iter
	      (fun script ->
		 pr "%6s[%20s] " lang script;
		 time (cmd script fn)
	      ) scripts
	 )
	 langs;
       pr "====================================\n"
    )
    args