diff --git a/bench/Makefile b/bench/Makefile index cad3a08a6..17ba14f4b 100644 --- a/bench/Makefile +++ b/bench/Makefile @@ -1,25 +1,25 @@ -.PHONY: clean +.PHONY: clean OUT = bench.exe -LAMA_CMXES = ../src/Language.cmx +LAMA_CMXES = ../src/Language.cmx OCAMLC = ocamlfind c OCAMLOPT = ocamlfind opt -BFLAGS += -package GT,ostap,re,benchmark -I ../src -rectypes -g +BFLAGS += -package GT,ostap,re,benchmark,str -I ../src -rectypes -g GENERATED = Pprint_gt.ml Pprint_default.ml all: $(OUT) bench_main.cmx: Pprint_gt.cmx Pprint_default.cmx -$(OUT): Pprint_gt.cmx Pprint_default.cmx bench_main.cmx +$(OUT): Pprint_gt.cmx Pprint_default.cmx bench_main.cmx $(OCAMLOPT) $(BFLAGS) $(LAMA_CMXES) -linkpkg $^ -o $@ - + clean: $(RM) *.cmi *.cmo *.cmx *.annot *.o *.opt *.byte *~ .depend $(OUT) $(GENERATED) %.cmi: %.ml $(OCAMLC) -c $(BFLAGS) $< - + %.cmx: %.ml $(OCAMLOPT) -c $(BFLAGS) $< @@ -31,4 +31,3 @@ Pprint_gt.ml: pp_gt.m4 p.ml ############### Pprint_default.ml: pp_default.m4 p.ml m4 $< p.ml > $@ - diff --git a/bench/bench_main.ml b/bench/bench_main.ml index 5d7c1bc9a..127ec81f9 100644 --- a/bench/bench_main.ml +++ b/bench/bench_main.ml @@ -1,10 +1,34 @@ open Benchmark -let () = +(* How many repetitions should be performed *) +let repeat = 2 +(* How nuch time we should spent on benchmark *) +let timeout = 2 + +let dirname,filenames = + let dirname = + let path1 = "./stdlib" in + let path2 = "../stdlib" in + if Sys.(file_exists path1 && is_directory path1) then path1 + else if Sys.(file_exists path2 && is_directory path2) then path2 + else failwith (Printf.sprintf "Can't find a directory '%s' or '%s'" path1 path2) + in + Format.printf "Looking for samples from: '%s'\n%!" dirname; + let files = + let fs = Sys.readdir dirname in + let r = Str.regexp ".*\\.lama$" in + List.filter (fun s -> (Str.string_match r s 0) && s <> "Ostap.lama") (Array.to_list fs) + in + Format.printf "Tests found: %s\n%!" (GT.show GT.list (GT.show GT.string) files); + (dirname,files) + + +let bench_file file = + Format.printf "Benchmarking file `%s`\n%!" file; let options = object method is_workaround = false - method get_infile = "stdlib/List.lama" - method get_include_paths = ["./stdlib"; "runtime"] + method get_infile = Printf.sprintf "%s/%s" dirname file + method get_include_paths = [dirname; Printf.sprintf "%s/../runtime" dirname] end in let ast = try match Language.run_parser options with @@ -32,6 +56,7 @@ let () = failwith "Two printers doesn't behave the same" end in + Gc.full_major (); let run_gt () = let _:string = Format.asprintf "%a" Pprint_gt.pp (snd ast) in () @@ -41,9 +66,11 @@ let () = () in - let res = throughputN ~repeat:1 1 + let res = throughputN ~style:Nil ~repeat timeout [ ("GT", run_gt, ()) ; ("Default", run_default, ()) ] in tabulate res + +let () = List.iter bench_file filenames