Commit a49c4f2d authored by Pietro Abate's avatar Pietro Abate

[r2003-06-08 10:12:43 by cvscast] addrbook bench

Original author: cvscast
Date: 2003-06-08 10:12:44+00:00
parent 91aa8db9
split:
ocaml unix.cma bench.ml | tee split.results
ocaml unix.cma bench.ml split 0,10,50,100,500,1000 \
split*.cd split*.q split*.xsl \
| tee split.results
addrbook:
ocaml unix.cma bench.ml addrbook 0,1000,5000,10000,50000,100000 \
addrbook*.cd addrbook*.xsl \
| tee addrbook.results
clean:
rm -f split.*.xml addrbook.*.xml
rm -f *~
rm -f *.results
let random_string n =
let s = String.create n in
for i = 0 to n - 1 do
s.[i] <- Char.chr (65 + (Random.int 26))
done;
s;;
let nb = int_of_string Sys.argv.(1);;
print_string "<?xml version=\"1.0\" encoding=\"UTF-8\"?><addrbook>";;
for i = 1 to nb do
Printf.printf "<person><name>%s</name>" (random_string 20);
if Random.int 2 = 0 then Printf.printf "<tel>%s</tel>" (random_string 20);
for j = 1 to (Random.int 4) do
Printf.printf "<email>%s</email>" (random_string 20)
done;
Printf.printf "</person>"
done;;
print_string "</addrbook>";;
type Addrbook = <addrbook>[Person*]
type Person = <person>[(Name Tel? Email* )]
type Name = <name>String
type Tel = <tel>String
type Email = <email>String
let mkTelbook ([Person*] -> [<entry>[Name Tel] *])
| [ <person>[ (n & Name) (t & Tel) ; _ ]; rest] ->
[ <entry>[n t]; mkTelbook rest ]
| [ <person>[ Name ; _ ] ; rest] -> mkTelbook rest
| [] -> []
match argv with
| [ f ] ->
(match load_xml f with
| <addrbook>(x & [Person*]) -> mkTelbook x
| _ -> raise "Invalid document")
| _ -> raise "Invalid command line"
import "xml.q"
type Addrbook = addrbook[Person*]
type Person = person[(Name,Tel?,Email* )]
type Name = name[String]
type Tel = tel[String]
type Email = email[String]
fun mkTelbook (val ps as Person* ) : entry[(Name,Tel)]* =
match ps with
person[name[val n], tel[val t],val e],val rest
-> entry[name[n], tel[t]], mkTelbook(rest)
| person[name[val n],val e],val rest
-> mkTelbook(rest)
| ()
-> ()
let val _ =
match argv() with
val fn as String ->
( match load_xml(fn) with
addrbook[val p as Person*] -> mkTelbook(p)
| Any -> raise("Invalid document") )
| Any -> raise("Invalid command line")
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<doc>
<xsl:apply-templates select="*"/>
</doc>
</xsl:template>
<xsl:template match="person">
<xsl:if test="tel">
<entry>
<name>
<xsl:value-of select="name"/>
</name>
<tel>
<xsl:value-of select="tel"/>
</tel>
</entry>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
type Addrbook = <addrbook>[Person*]
type Person = <person>[(Name Tel? Email* )]
type Name = <name>String
type Tel = <tel>String
type Email = <email>String
let mkTelbook ([Person*] -> [<entry>[Name Tel] *])
| [ <_>[ n (t & <tel>_) ; _ ]; rest] -> [ <entry>[n t]; mkTelbook rest ]
| [ _ ; rest] -> mkTelbook rest
| [] -> []
match argv with
| [ f ] ->
(match load_xml f with
| <addrbook>(x & [Person*]) -> mkTelbook x
| _ -> raise "Invalid document")
| _ -> raise "Invalid command line"
import "xml.q"
type Addrbook = addrbook[Person*]
type Person = person[(Name,Tel?,Email* )]
type Name = name[String]
type Tel = tel[String]
type Email = email[String]
fun mkTelbook (val ps as Person* ) : entry[(Name,Tel)]* =
filter ps {
( person[name[val n], tel[val t], val e]
{ entry[name[n], tel[t]] }
| person[name[val n], val e as Email*]
{ () }
)*
}
let val _ =
match argv() with
val fn as String ->
( match load_xml(fn) with
addrbook[val p as Person*] -> mkTelbook(p)
| Any -> raise("Invalid document") )
| Any -> raise("Invalid command line")
type Addrbook = <addrbook>[Person*]
type Person = <person>[(Name Tel? Email* )]
type Name = <name>String
type Tel = <tel>String
type Email = <email>String
let mkTelbook (l : [Person*]) : [<entry>[Name Tel] *] =
transform l with <person>[ (n & Name) (t & Tel) ; _ ] -> [ <entry>[n t] ]
match argv with
| [ f ] ->
(match load_xml f with
| <addrbook>(x & [Person*]) -> mkTelbook x
| _ -> raise "Invalid document")
| _ -> raise "Invalid command line"
import "xml.q"
type Addrbook = addrbook[Person*]
type Person = person[(Name,Tel?,Email* )]
type Name = name[String]
type Tel = tel[String]
type Email = email[String]
fun mkTelbook (val ps as Person* ) : entry[(Name,Tel)]* =
filter ps {
person[Name,Email*]*,
person[name[val n], tel[val t], val e], val rest
{ entry[name[n], tel[t]], mkTelbook(rest) }
| person[Name,Email*]*
{ () }
}
let val _ =
match argv() with
val fn as String ->
( match load_xml(fn) with
addrbook[val p as Person*] -> mkTelbook(p)
| Any -> raise("Invalid document") )
| Any -> raise("Invalid command line")
type Addrbook = <addrbook>[Person*]
type Person = <person>[(Name Tel? Email* )]
type Name = <name>String
type Tel = <tel>String
type Email = <email>String
let mkTelbook (l : [Person*]) : [<entry>[Name Tel] *] =
transform l with <_>[ n (t & <tel>_) ; _ ] -> [ <entry>[n t] ]
match argv with
| [ f ] ->
(match load_xml f with
| <addrbook>(x & [Person*]) -> mkTelbook x
| _ -> raise "Invalid document")
| _ -> raise "Invalid command line"
......@@ -3,32 +3,71 @@ open Printf
let time_cmd = "/usr/bin/time"
let cduce_cmd = "../cduce"
let xduce_cmd = "/home/frisch/xduce-0.4.0/xduce.opt"
let xduce_024_cmd = "/home/frisch/xduce-0.2.4/xduce.opt"
let xslt_cmd = "xsltproc"
let gen = "split.ml"
let xml = "split"
let cduce = [ "split0.cd"; "split1.cd"; "split2.cd"; "split3.cd" ]
let xslt = [ "split1.xsl"; "split2.xsl" ]
let xduce = [] (* [ "split1.q"; "split2.q"; "split3.q" ] *)
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 ]
let args = [ 0; 10 ; 50; 100; 500; 1000; (* 5000 *) ]
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)
let sp = sprintf
let langs =
[
"CDuce", cduce,
"CDuce", ".cd",
(fun script xml ->
sp "%s --quiet %s --arg %s" cduce_cmd script xml);
sp "%s --pxp --quiet %s --arg %s" cduce_cmd script xml);
"CDuce+expat", cduce,
"CDuce+expat", ".cd",
(fun script xml ->
sp "%s --expat --quiet %s --arg %s" cduce_cmd script xml);
"XDuce", xduce,
"XDuce 0.4.0", ".q",
(fun script xml ->
sp "%s %s %s" xduce_cmd script xml);
sp "%s %s %s" xduce_cmd script xml);
"XSLT", xslt,
"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",
(fun script xml ->
sp "%s --noout %s %s" xslt_cmd script xml);
]
......@@ -37,16 +76,9 @@ let langs =
let pr = printf
let rep = 1
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"
let time s =
let s = sp "%s -p %s 2>&1" time_cmd s in
(* pr "Running: %s\n" s; *)
flush stdout;
for i = 1 to rep do
let ic = Unix.open_process_in s in
......@@ -55,7 +87,9 @@ let time s =
let sys = input_line ic in
match (Unix.close_process_in ic) with
| Unix.WEXITED 0 ->
pr "%s,%s " (extract "real " real) (extract "user " user);
pr "%s,%s "
(extract_prefix "user " user)
(extract_prefix "real " real);
flush stdout;
| _ ->
pr "err"
......@@ -70,18 +104,19 @@ let () =
List.iter
(fun s ->
let fn = sp "%s.%i.xml" xml s in
run (sp "ocaml %s %i > %s" gen s fn);
if not (Sys.file_exists fn) then
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) ->
(fun (lang, ext, cmd) ->
List.iter
(fun script ->
pr "%20s[%20s] " lang script;
time (cmd script fn)
) scripts
(fun file ->
pr "%20s[%20s] " lang file;
time (cmd file fn)
) (scripts ext)
)
langs;
pr "====================================\n"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment