bench.ml 2.91 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 expat", ".cd",
55
56
57
    (fun script xml -> 
       sp "%s --expat --quiet %s --arg %s" cduce_cmd script xml);

58
    "XDuce 0.4.0", ".q",
59
    (fun script xml -> 
60
       sp "%s %s %s" xduce_cmd script xml); 
61

62
63
64
65
66
67
68
69
70
    "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",
71
    (fun script xml -> 
72
       sp "%s --noout %s %s" xslt_cmd script xml);
73
74
75
76
  ]
  

let pr = printf
77
let rep = 3
78

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