bench.ml 3.04 KB
Newer Older
1 2
open Printf

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

9 10 11 12 13 14
let rec split c s =
  try 
    let i = String.index s c in
    (String.sub s 0 i) :: 
    (split c (String.sub s (i + 1) (String.length s - i - 1)))
  with Not_found -> [ s ]
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
let has_prefix pre s =
  let ls = String.length s in
  let lpre = String.length pre in
  (ls >= lpre) && (String.sub s 0 lpre) = pre

let extract_prefix 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"

let has_suffix pre s = 
  let ls = String.length s in
  let lpre = String.length pre in
  (ls >= lpre) && (String.sub s (ls - lpre) lpre) = pre

let name, args, scripts = 
  match (Array.to_list Sys.argv) with
    | _ :: name :: args :: scripts -> (name,args,scripts)
    | _ -> 
	Printf.eprintf "Please specify bench name and size list";
	exit 1

let scripts ext = List.filter (has_suffix ext) scripts

let gen = name ^ ".ml"
let xml = name

let args =  List.map int_of_string (split ',' args)
46 47 48 49

let sp = sprintf
let langs = 
  [
50
(*    "CDuce PXP", ".cd",
51
    (fun script xml -> 
52
       sp "%s --pxp --quiet %s --arg %s" cduce_cmd script xml);  *)
53

54
    "CDuce", ".cd",
55
    (fun script xml -> 
56 57
       sp "%s %s --no ocaml --arg %s" cduce_cmd script xml);
(*    "CDuce.old", ".cd",
58
    (fun script xml -> 
59
       sp "%s --quiet %s --arg %s" (cduce_cmd^".old") script xml);*)
60

61
    "XDuce 0.4.0", ".q",
62
    (fun script xml -> 
63
       sp "%s %s %s" xduce_cmd script xml); 
64

65 66 67 68 69 70 71 72 73
    "XDuce 0.2.4", ".q",
    (fun script xml -> 
       sp "%s %s %s" xduce_024_cmd script xml); 

    "XDuce 0.2.4 - patopt", ".q",
    (fun script xml -> 
       sp "%s %s -patopt %s" xduce_024_cmd script xml);

    "XSLT", ".xsl",
74
    (fun script xml -> 
75
       sp "%s --noout %s %s" xslt_cmd script xml);
76 77 78 79
  ]
  

let pr = printf
80
let rep = 3
81

82
let time s =
83
  let s = sp "%s -p %s 2>&1" time_cmd s in
84
(*  pr "Running: %s\n" s;  *)
85 86 87
  flush stdout;
  for i = 1 to rep do
    let ic = Unix.open_process_in s in
88 89 90
    let real = input_line ic in
    let user = input_line ic in
    let sys  = input_line ic in
91 92
    match  (Unix.close_process_in ic) with
      | Unix.WEXITED 0 ->
93 94 95
	  pr "%s,%s " 
	    (extract_prefix "user " user)
	    (extract_prefix "real " real); 
96 97 98
	  flush stdout;
      | _ ->
	  pr "err"
99 100 101 102 103 104 105 106 107 108 109
  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
110 111
       if not (Sys.file_exists fn) then
	 run (sp "ocaml %s %i > %s" gen s fn);
112 113 114
       let ic = open_in fn in
       let size = in_channel_length ic in
       close_in ic;
115
       pr "XML size = %i; records = %i\n" size s;
116
       List.iter
117
	 (fun (lang, ext, cmd) ->
118
	    List.iter
119 120 121 122
	      (fun file ->
		 pr "%20s[%20s] " lang file;
		 time (cmd file fn)
	      ) (scripts ext)
123 124 125 126 127
	 )
	 langs;
       pr "====================================\n"
    )
    args