Benchmarking many files at once

Signed-off-by: Kakadu <Kakadu@pm.me>
This commit is contained in:
Kakadu 2020-10-25 18:20:19 +03:00
parent 62d1aa7316
commit ae6fad97c6
2 changed files with 37 additions and 11 deletions

View file

@ -4,7 +4,7 @@ OUT = bench.exe
LAMA_CMXES = ../src/Language.cmx LAMA_CMXES = ../src/Language.cmx
OCAMLC = ocamlfind c OCAMLC = ocamlfind c
OCAMLOPT = ocamlfind opt 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 GENERATED = Pprint_gt.ml Pprint_default.ml
all: $(OUT) all: $(OUT)
@ -31,4 +31,3 @@ Pprint_gt.ml: pp_gt.m4 p.ml
############### ###############
Pprint_default.ml: pp_default.m4 p.ml Pprint_default.ml: pp_default.m4 p.ml
m4 $< p.ml > $@ m4 $< p.ml > $@

View file

@ -1,10 +1,34 @@
open Benchmark 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 let options = object
method is_workaround = false method is_workaround = false
method get_infile = "stdlib/List.lama" method get_infile = Printf.sprintf "%s/%s" dirname file
method get_include_paths = ["./stdlib"; "runtime"] method get_include_paths = [dirname; Printf.sprintf "%s/../runtime" dirname]
end in end in
let ast = let ast =
try match Language.run_parser options with try match Language.run_parser options with
@ -32,6 +56,7 @@ let () =
failwith "Two printers doesn't behave the same" failwith "Two printers doesn't behave the same"
end end
in in
Gc.full_major ();
let run_gt () = let run_gt () =
let _:string = Format.asprintf "%a" Pprint_gt.pp (snd ast) in let _:string = Format.asprintf "%a" Pprint_gt.pp (snd ast) in
() ()
@ -41,9 +66,11 @@ let () =
() ()
in in
let res = throughputN ~repeat:1 1 let res = throughputN ~style:Nil ~repeat timeout
[ ("GT", run_gt, ()) [ ("GT", run_gt, ())
; ("Default", run_default, ()) ; ("Default", run_default, ())
] ]
in in
tabulate res tabulate res
let () = List.iter bench_file filenames