Commit 4cc44b7c authored by POTTIER Francois's avatar POTTIER Francois

The speed test is ready.

parent 2de85e1f
...@@ -23,3 +23,7 @@ gene Another version of the calc demo, bundled ...@@ -23,3 +23,7 @@ gene Another version of the calc demo, bundled
with its own random generator of (long) with its own random generator of (long)
test inputs. test inputs.
speed.sh Runs the speed test.
speed.ml Used by speed.sh.
...@@ -5,9 +5,12 @@ ...@@ -5,9 +5,12 @@
. ./config.sh . ./config.sh
# Removing $BUILD ensures that Menhir is rebuilt from scratch, but this is
# a bit slow.
# rm -rf $BUILD
# Recompile. # Recompile.
rm -f $SRC/installation.ml rm -f $SRC/installation.ml
rm -rf $BUILD
echo "Building Menhir..." echo "Building Menhir..."
if ! make -C $SRC >/dev/null ; then if ! make -C $SRC >/dev/null ; then
echo "Could not build Menhir. Stop." echo "Could not build Menhir. Stop."
......
SRC=../src SRC=../src
BUILD=$SRC/_stage1 BUILD=$SRC/_stage1
# An absolute path for Menhir.
MENHIR=$BUILD/menhir.native MENHIR=$BUILD/menhir.native
if which -s greadlink ; then
MENHIR=`greadlink -f $MENHIR`
else
MENHIR=`readlink -f $MENHIR`
fi
CALC=calc CALC=calc
DATA=calc-data DATA=calc-data
GENE=gene
_build _build
*.native *.native
*.out
*.time
...@@ -4,9 +4,10 @@ ...@@ -4,9 +4,10 @@
# This is useful because ocamlbuild descends into _build. # This is useful because ocamlbuild descends into _build.
ifndef MENHIR ifndef MENHIR
READLINK := $(shell if which -s greadlink ; then echo greadlink ; else echo readlink ; fi) READLINK := $(shell if which -s greadlink ; then echo greadlink ; else echo readlink ; fi)
MENHIR := $(shell $(READLINK) -f ../../src/_stage1/menhir.native) MENHIR := $(shell $(READLINK) -f ../../src/_stage1/menhir.native) \
--table
endif endif
OCAMLBUILD := ocamlbuild -use-ocamlfind -menhir "$(MENHIR) --table" OCAMLBUILD := ocamlbuild -use-ocamlfind -menhir "$(MENHIR)"
all: all:
$(OCAMLBUILD) gene.native $(OCAMLBUILD) gene.native
......
open Printf
(* Read one floating-point in a file. *)
let read f =
let c = open_in f in
let s = input_line c in
close_in c;
float_of_string s
let dry =
read "gene/dry.time"
let code =
read "gene/code.time"
let table =
read "gene/table.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);
printf "The table back-end is %.1f times slower than the code back-end.\n" ((table -. dry) /. (code -. dry));
flush stdout
#!/bin/bash
# This script runs the speed test in gene/ (where the test input
# is a randomly-generated arithmetic expression).
. ./config.sh
# The time command.
if which -s gtime ; then
TIME=gtime
else
TIME=time
fi
# Make sure Menhir and MenhirLib are up-to-date.
./build.sh
# Build the parser with the code back-end.
echo "Building (code)..."
make -C $GENE clean >/dev/null
make -C $GENE MENHIR="$MENHIR" >/dev/null
# Dry run (measures the random generation time).
echo Dry run:
$TIME -f "%U" $GENE/gene.native --dry-run 2> $GENE/dry.time
cat $GENE/dry.time
# Run the code back-end.
echo Code back-end:
$TIME -f "%U" $GENE/gene.native > $GENE/code.out 2> $GENE/code.time
cat $GENE/code.time
# Build the parser with the table back-end.
echo "Building (table)..."
make -C $GENE clean >/dev/null
make -C $GENE MENHIR="$MENHIR --table" >/dev/null
# Run the table back-end.
echo Table back-end:
$TIME -f "%U" $GENE/gene.native > $GENE/table.out 2> $GENE/table.time
cat $GENE/table.time
# Avoid a gross mistake.
if ! diff -q $GENE/code.out $GENE/table.out ; then
echo CAUTION: the code and table back-ends disagree!
echo Code:
cat $GENE/code.out
echo Table:
cat $GENE/table.out
exit 1
fi
# Compute some statistics.
ocaml speed.ml
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# Build the parser with the code back-end and run it. # Build the parser with the code back-end and run it.
echo "Building and running (code)..." echo "Building and running (code)..."
make -C $CALC clean >/dev/null make -C $CALC clean >/dev/null
make -C $CALC MENHIR="../$MENHIR --trace" >/dev/null make -C $CALC MENHIR="$MENHIR --trace" >/dev/null
for f in $DATA/*.real.in ; do for f in $DATA/*.real.in ; do
b=${f%.in} b=${f%.in}
$CALC/calc < $f > $b.code.out 2> $b.code.err $CALC/calc < $f > $b.code.out 2> $b.code.err
...@@ -21,7 +21,7 @@ done ...@@ -21,7 +21,7 @@ done
# Build the parser with the table back-end and run it. # Build the parser with the table back-end and run it.
echo "Building and running (table)..." echo "Building and running (table)..."
make -C $CALC clean >/dev/null make -C $CALC clean >/dev/null
make -C $CALC MENHIR="../$MENHIR --trace --table" >/dev/null make -C $CALC MENHIR="$MENHIR --trace --table" >/dev/null
for f in $DATA/*.real.in ; do for f in $DATA/*.real.in ; do
b=${f%.in} b=${f%.in}
$CALC/calc < $f > $b.table.out 2> $b.table.err $CALC/calc < $f > $b.table.out 2> $b.table.err
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# Build the parser with the code back-end and run it. # Build the parser with the code back-end and run it.
echo "Building (code)..." echo "Building (code)..."
make -C $CALC clean >/dev/null make -C $CALC clean >/dev/null
make -C $CALC MENHIR="../$MENHIR --trace" >/dev/null make -C $CALC MENHIR="$MENHIR --trace" >/dev/null
for f in $DATA/*.real.in ; do for f in $DATA/*.real.in ; do
b=${f%.in} b=${f%.in}
echo "($b) Reconstructing reference output and trace..." echo "($b) Reconstructing reference output and trace..."
......
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