Commit 64fec40e authored by POTTIER Francois's avatar POTTIER Francois
Browse files

[make speed]: perform internal time measurements. Do not subtract the time of...

[make speed]: perform internal time measurements. Do not subtract the time of the dry run. Perform 10 runs in succession. All this should contribute to more stable performance data.
parent 5ab50a4d
Pipeline #122746 passed with stages
in 26 seconds
......@@ -7,31 +7,18 @@ let read f =
close_in c;
float_of_string s
let dry =
read "src/dry.time"
let code =
read "src/code.time"
let table =
read "src/table.time"
let ocamlyacc =
try
Some (read "src/ocamlyacc.time")
with Sys_error _ ->
None
let optionally o f =
match o with Some x -> f x | None -> ()
read "src/ocamlyacc.time"
let () =
printf "Test input generation takes %.2f seconds.\n" dry;
printf "Parsing with the code back-end takes %.2f seconds.\n" (code -. dry);
printf "Parsing with the table back-end takes %.2f seconds.\n" (table -. dry);
optionally ocamlyacc (fun ocamlyacc ->
printf "Parsing with ocamlyacc takes %.2f seconds.\n" (ocamlyacc -. dry);
);
printf "The table back-end is %.1f times slower than the code back-end.\n" ((table -. dry) /. (code -. dry));
optionally ocamlyacc (fun ocamlyacc ->
printf "ocamlyacc is %.1f times slower than the code back-end.\n" ((ocamlyacc -. dry) /. (code -. dry));
printf "ocamlyacc is %.1f times faster than the table back-end.\n" ((table -. dry) /. (ocamlyacc -. dry));
);
printf "Parsing with the code back-end takes %.2f seconds.\n" code;
printf "Parsing with the table back-end takes %.2f seconds.\n" table;
printf "Parsing with ocamlyacc takes %.2f seconds.\n" ocamlyacc;
printf "The table back-end is %.1f times slower than the code back-end.\n" (table /. code);
printf "ocamlyacc is %.1f times slower than the code back-end.\n" (ocamlyacc /. code);
printf "ocamlyacc is %.1f times faster than the table back-end.\n" (table /. ocamlyacc);
flush stdout
......@@ -18,19 +18,17 @@ rm -f src/*.time
for size in 1000000 5000000 10000000 ; do
echo "Test size: $size"
# Dry run (measures the random generation time).
echo Dry run:
$TIME -f "%U" src/code/gene.exe --size $size --dry-run 2> src/dry.time
cat src/dry.time
# echo Dry run:
# $TIME -f "%U" src/code/gene.exe --size $size --dry-run
# Run the code back-end.
echo Code back-end:
$TIME -f "%U" src/code/gene.exe --size $size > src/code.out 2> src/code.time
src/code/gene.exe --size $size > src/code.out 2> src/code.time
cat src/code.time
# Run the table back-end.
echo Table back-end:
$TIME -f "%U" src/table/gene.exe --size $size > src/table.out 2> src/table.time
src/table/gene.exe --size $size > src/table.out 2> src/table.time
cat src/table.time
# Avoid a gross mistake.
......@@ -45,9 +43,19 @@ for size in 1000000 5000000 10000000 ; do
# Run the ocamlyacc parser.
echo "ocamlyacc:"
$TIME -f "%U" src/ocamlyacc/gene.exe --size $size > src/ocamlyacc.out 2> src/ocamlyacc.time
src/ocamlyacc/gene.exe --size $size > src/ocamlyacc.out 2> src/ocamlyacc.time
cat src/ocamlyacc.time
# Avoid another mistake.
if ! diff -q src/code.out src/ocamlyacc.out ; then
echo CAUTION: Menhir and ocamlyacc disagree!
echo Menhir:
cat src/code.out
echo ocamlyacc:
cat src/ocamlyacc.out
exit 1
fi
# Compute some statistics.
ocaml speed.ml
......
......@@ -7,4 +7,5 @@
(executable
(name gene)
(libraries unix)
)
......@@ -43,6 +43,11 @@ let dry_run =
let seed =
ref 61112962
(* [--runs] allows the desired number of runs to be set via the command line. *)
let runs =
ref 10
(* [--size] allows the size of the randomly-generated expression to be
set via the command line. *)
......@@ -52,6 +57,7 @@ let size =
let options = Arg.align [
"--dry-run", Arg.Set dry_run, "Run only the generator, not the parser";
"--seed", Arg.Set_int seed, sprintf "<seed> Set the random seed (%d)" !seed;
"--runs", Arg.Set_int runs, sprintf "<runs> Set the number of runs (%d)" !runs;
"--size", Arg.Set_int size, sprintf "<size> Set the size of the test (%d)" !size;
]
......@@ -76,10 +82,8 @@ let () =
Gc.major()
let () =
if !dry_run then begin
printf "Done.\n";
if !dry_run then
exit 0
end
let lexer lexbuf =
let pos = lexbuf.lex_curr_pos in
......@@ -99,5 +103,14 @@ let new_lexbuf () =
lexbuf
let () =
printf "%d\n%!"
(Parser.main lexer (new_lexbuf()))
(* Running the parser several times in succession (without re-generating the
random data, and without explicitly invoking the GC between runs) should
allow us to obtain slightly more stable timings. *)
let chrono = Time.fresh() in
Time.chrono chrono (fun () ->
for _run = 0 to !runs do
printf "%d\n%!"
(Parser.main lexer (new_lexbuf()))
done
);
Time.display stderr chrono
......@@ -5,4 +5,5 @@
(executable
(name gene)
(libraries unix)
)
......@@ -8,5 +8,5 @@
(executable
(name gene)
(libraries menhirLib)
(libraries unix menhirLib)
)
open Unix
open Printf
type chrono =
float ref
let fresh () =
ref 0.
let chrono (chrono : float ref) (task : unit -> 'a) : 'a =
let times1 = times() in
let result = task() in
let times2 = times() in
chrono := !chrono +. times2.tms_utime -. times1.tms_utime;
result
let display channel (chrono : float ref) =
fprintf channel "%.02f\n" !chrono
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