bench.ml 1.9 KB
Newer Older
1 2
open Printf

3 4 5 6 7
let time_cmd = "/usr/bin/time"
let cduce_cmd = "../cduce"
let xduce_cmd = "/home/frisch/xduce-0.4.0/xduce.opt"
let xslt_cmd = "xsltproc"

8 9
let gen = "split.ml"
let xml = "split"
10
let cduce = [ "split0.cd"; "split1.cd"; "split2.cd"; "split3.cd" ]
11
let xslt = [ "split1.xsl"; "split2.xsl" ]
12 13 14
let xduce = [] (* [ "split1.q"; "split2.q"; "split3.q" ] *)

let args = [ 0; 10 ; 50; 100; 500; 1000; (* 5000 *) ]
15 16 17 18 19 20

let sp = sprintf
let langs = 
  [
    "CDuce", cduce,
    (fun script xml -> 
21
       sp "%s --quiet %s --arg %s" cduce_cmd script xml);
22 23 24

    "XDuce", xduce,
    (fun script xml -> 
25
       sp "%s %s %s" xduce_cmd script xml);
26 27 28

    "XSLT", xslt,
    (fun script xml -> 
29
       sp "%s --noout %s %s" xslt_cmd script xml);
30 31 32 33 34
  ]
  

let pr = printf
let rep = 1
35 36 37 38 39 40 41 42 43

let extract pre s =
  let ls = String.length s in
  let lpre = String.length pre in
  if (ls >= lpre) && (String.sub s 0 lpre) = pre then
    (String.sub s lpre (ls - lpre))
  else
    failwith "Invalid string"

44
let time s =
45
  let s = sp "%s -p %s 2>&1" time_cmd s in
46 47 48
  flush stdout;
  for i = 1 to rep do
    let ic = Unix.open_process_in s in
49 50 51
    let real = input_line ic in
    let user = input_line ic in
    let sys  = input_line ic in
52 53
    match  (Unix.close_process_in ic) with
      | Unix.WEXITED 0 ->
54
	  pr "%s,%s " (extract "real " real) (extract "user " user);
55 56 57
	  flush stdout;
      | _ ->
	  pr "err"
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
  done;
  pr "\n"

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