bench.ml 1.81 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
10
11
12
13
14
15
16
17
18
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 -> 
19
       sp "%s --quiet %s --arg %s" cduce_cmd script xml);
20
21
22

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

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

let pr = printf
let rep = 1
33
34
35
36
37
38
39
40
41

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"

42
let time s =
43
  let s = sp "%s -p %s 2>&1" time_cmd s in
44
45
46
  flush stdout;
  for i = 1 to rep do
    let ic = Unix.open_process_in s in
47
48
49
    let real = input_line ic in
    let user = input_line ic in
    let sys  = input_line ic in
50
    ignore (Unix.close_process_in ic);
51
    pr "%s,%s " (extract "real" real) (extract "user" user);
52
53
54
55
56
57
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
    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