Permalink
Browse files

Initial commit

  • Loading branch information...
raphael-proust committed Aug 12, 2011
0 parents commit 50a5f8108307f51a0470cfd1cd8e916a0220c505
@@ -0,0 +1,43 @@
OPTIONS= -unsafe
UNIX= -package unix unix.cmxa
PCRE= -package pcre pcre.cmxa
STR = -package str str.cmxa
REGEXP_DIR= regexp/_build
REGEXP= regexp.cmx
MLOBJS= common.cmx re_string_regexp_bench.cmx re_regexp_bench.cmx pcre_nogroup_regexp_bench.cmx pcre_regexp_bench.cmx str_regexp_bench.cmx
TARGET= driver_unix.native
all: $(TARGET)
$(REGEXP):
make -C regexp
re_regexp_bench.cmx: $(REGEXP) common.cmx re_regexp_bench.ml
ocamlfind ocamlopt $(OPTIONS) $(UNIX) -I $(REGEXP_DIR) -c $^ -o $@
re_string_regexp_bench.cmx: $(REGEXP) common.cmx re_string_regexp_bench.ml
ocamlfind ocamlopt $(OPTIONS) $(UNIX) -I $(REGEXP_DIR) -c $^ -o $@
pcre_regexp_bench.cmx: common.cmx pcre_regexp_bench.ml
ocamlfind ocamlopt $(OPTIONS) $(UNIX) $(PCRE) -c $^ -o $@
pcre_nogroup_regexp_bench.cmx: common.cmx pcre_nogroup_regexp_bench.ml
ocamlfind ocamlopt $(OPTIONS) $(UNIX) $(PCRE) -c $^ -o $@
str_regexp_bench.cmx: common.cmx str_regexp_bench.ml
ocamlfind ocamlopt $(OPTIONS) $(UNIX) $(STR) -c $^ -o $@
$(TARGET): $(REGEXP) $(MLOBJS) $(subst native,ml,$(TARGET))
ocamlfind ocamlopt $(OPTIONS) $(UNIX) $(STR) $(PCRE) -I $(REGEXP_DIR) $^ -o $@
%.cmx: %.ml
ocamlfind ocamlopt $(OPTIONS) -c -g $<
clean:
rm -rf $(TARGET) myocamlbuild.ml *.cm* *.o
rm -rf _build regexp/_build
@@ -0,0 +1,55 @@
let urls =
[ "http://ocsigen.org"
; "http://openmirage.org"
; "http://ddg.gg"
; "http://github.com"
; "http://www.ocsigen.org"
; "http://www.openmirage.org"
; "http://www.ddg.gg"
; "http://www.github.com"
; "http://caml.inria.fr"
; "http://www.lri.fr/~marche/regexp/regexp-0.3.tar.gz"
; "http://ocsigen.org/lwt/api/Lwt"
; "http://www.lri.fr/~marche/regexp/regexp-0.3.tar.gz"
; "http://ocsigen.org/lwt/api/Lwt"
; "http://ocsi"
; "http://nodejs.org/docs/v0.3.1/api/buffers.html"
; "http://help.ubuntu.com/community/UpgradeNotes"
; "http://www-uxsup.csx.cam.ac.uk/pub/linux/ubuntu/"
; "http://www-uxsup.csx.cam.ac.uk/pub/linux/ubuntu"
; "http://extras.ubuntu.com/ubuntu"
; "http://ocsigen.org/js_of_ocaml/sources/lib/regexp.mli"
; "http://www.lri.fr/~marche/regexp/regexp-0.3.tar.gz"
; "http://ocsigen.org/lwt/api/Lwt"
; "http://ocsigen.org/js_of_ocaml/sources/lib/regexp.mli"
; "http:/nodejs.org/docs/v0.3.1/api/buffers.html"
; "http://help.ubuntu.com/community/UpgradeNotes"
; "http://www-uxsup.csx.cam.ac.uk/pub/linux/ubuntu/"
; "http://www-uxsup.csx.cam.ac.uk/pub/linux/ubuntu"
; "http://extras.ubuntu.com/ubuntu"
; "http/nodejs.org/docs/v0.3.1/api/buffers.html"
; "http://help.ubuntu.com/community/UpgradeNotes"
; "http://www-uxsup.csx.cam.ac.uk/pub/linux/ubuntu/"
; "ht//www-uxsup.csx.cam.ac.uk/pub/linux/ubuntu"
; "httpxtras://.ubuntu.com/ubuntu"
; "http://twitter.com"
]
let time f =
let t0 = Unix.gettimeofday () in
ignore (f ());
let tf = Unix.gettimeofday () in
tf -. t0
let run_n f n =
let rec aux m =
if m >= n then
()
else
(ignore (f ()); aux (succ m))
in
aux 0
@@ -0,0 +1,147 @@
let get_int i = int_of_string (Sys.argv.(i))
let runs = get_int 1
let comps = get_int 2
let execs = get_int 3
let prep = try get_int 4 with _ -> 0
let prepend_0s i s = String.make i '0' ^ s
let urls =
List.map (prepend_0s prep)
[ "http://ocsigen.org"
; "http://openmirage.org"
; "http://ddg.gg"
; "http://github.com"
; "http://www.ocsigen.org"
; "http://www.openmirage.org"
; "http://www.ddg.gg"
; "http://www.github.com"
; "http://caml.inria.fr"
; "http://www.lri.fr/~marche/regexp/regexp-0.3.tar.gz"
; "http://ocsigen.org/lwt/api/Lwt"
; "http://www.lri.fr/~marche/regexp/regexp-0.3.tar.gz"
; "http://ocsigen.org/lwt/api/Lwt"
; "http://ocsi"
; "http://nodejs.org/docs/v0.3.1/api/buffers.html"
; "http://help.ubuntu.com/community/UpgradeNotes"
; "http://www-uxsup.csx.cam.ac.uk/pub/linux/ubuntu/"
; "http://www-uxsup.csx.cam.ac.uk/pub/linux/ubuntu"
; "http://extras.ubuntu.com/ubuntu"
; "http://ocsigen.org/js_of_ocaml/sources/lib/regexp.mli"
; "http://www.lri.fr/~marche/regexp/regexp-0.3.tar.gz"
; "http://ocsigen.org/lwt/api/Lwt"
; "http://ocsigen.org/js_of_ocaml/sources/lib/regexp.mli"
; "http:/nodejs.org/docs/v0.3.1/api/buffers.html"
; "http://help.ubuntu.com/community/UpgradeNotes"
; "http://www-uxsup.csx.cam.ac.uk/pub/linux/ubuntu/"
; "http://www-uxsup.csx.cam.ac.uk/pub/linux/ubuntu"
; "http://extras.ubuntu.com/ubuntu"
; "http/nodejs.org/docs/v0.3.1/api/buffers.html"
; "http://help.ubuntu.com/community/UpgradeNotes"
; "http://www-uxsup.csx.cam.ac.uk/pub/linux/ubuntu/"
; "ht//www-uxsup.csx.cam.ac.uk/pub/linux/ubuntu"
; "httpxtras://.ubuntu.com/ubuntu"
; "http://twitter.com"
]
let time f =
let t0 = Unix.gettimeofday () in
ignore (f ());
let tf = Unix.gettimeofday () in
tf -. t0
let run_n f n =
let rec aux m =
if m >= n then
()
else
(ignore (f ()); aux (succ m))
in
aux 0
let r () =
Gc.compact ();
let t =
(time (fun () ->
run_n
(fun () ->
let r = Str_regexp_bench.re () in
run_n (fun () -> Str_regexp_bench.f r urls) execs
)
comps
))
in
Printf.printf "%f %!" t;
Printf.eprintf ".%!";
Gc.compact ();
let t =
(time (fun () ->
run_n
(fun () ->
let r = Re_regexp_bench.re () in
run_n (fun () -> Re_regexp_bench.f r urls) execs
)
comps
))
in
Printf.printf "%f %!" t;
Printf.eprintf ".%!";
Gc.compact ();
let t =
(time (fun () ->
run_n
(fun () ->
let r = Re_string_regexp_bench.re () in
run_n (fun () -> Re_string_regexp_bench.f r urls) execs
)
comps
))
in
Printf.printf "%f %!" t;
Printf.eprintf ".%!";
Gc.compact ();
let t =
(time (fun () ->
run_n
(fun () ->
let r = Pcre_regexp_bench.re () in
run_n (fun () -> Pcre_regexp_bench.f r urls) execs
)
comps
))
in
Printf.printf "%f %!" t;
Printf.eprintf ".%!";
Gc.compact ();
let t =
(time (fun () ->
run_n
(fun () ->
let r = Pcre_nogroup_regexp_bench.re () in
run_n (fun () -> Pcre_nogroup_regexp_bench.f r urls) execs
)
comps
))
in
Printf.printf "%f\n%!" t;
Printf.eprintf ".%!";
()
let () = run_n r runs
@@ -0,0 +1,7 @@
let re () = Pcre.regexp "(?:0*)http://(?:(?:[0-9a-zA-Z.-])+)(?:(?:/.*)?)"
let m rex s = Pcre.pmatch ~rex s
let f r us = List.for_all (m r) us
@@ -0,0 +1,7 @@
let re () = Pcre.regexp "(0*)http://(([0-9a-zA-Z.-])+)((/.*)?)"
let m rex s = Pcre.pmatch ~rex s
let f r us = List.for_all (m r) us
@@ -0,0 +1,9 @@
set title "%%FILE%%"
set xlabel ""
set ylabel "time(s)"
plot "%%FILE%%" using (0):1 with points title "Str",\
"%%FILE%%" using (1):2 with points title "Regexp",\
"%%FILE%%" using (2):3 with points title "Regexp (w/ string parsing)",\
"%%FILE%%" using (3):4 with points title "Pcre",\
"%%FILE%%" using (4):5 with points title "Pcre (w/o grouping)"
@@ -0,0 +1,4 @@
for i in $(ls data/) ; do
sed "s/%%FILE%%/data\/$i/" plot.plt | gnuplot -persist
done
@@ -0,0 +1,31 @@
open Regexp
let re () = Re.compile
(Re.seq
(Re.star (Re.char '0'))
(Re.seq
(Re.string "http://")
(Re.seq
(Re.some
(Re.alt (Re.char_interv 'a' 'z')
(Re.alt (Re.char_interv 'A' 'Z')
(Re.alt (Re.char_interv '0' '9')
(Re.alt (Re.char '.') (Re.char '-')))))
)
(Re.opt
(Re.seq
(Re.char '/')
(Re.star (Re.char_interv (char_of_int 0) (char_of_int 255)))
)
)
)
)
)
let m r s = match Re.match_string r s 0 with
| None -> false
| Some e -> e = String.length s
let f r us = List.for_all (m r) us
@@ -0,0 +1,13 @@
open Regexp
let re () = Re.from_string "(0*)http://(([0-9a-zA-Z.\\-])+)((/.*)?)"
let m r s = match Re.match_string r s 0 with
| None -> false
| Some e -> e = String.length s
let f r us = List.for_all (m r) us
Oops, something went wrong.

0 comments on commit 50a5f81

Please sign in to comment.