speed.sh 2.14 KB
Newer Older
POTTIER Francois's avatar
POTTIER Francois committed
1 2 3 4 5 6 7 8
#!/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.
9
if command -v gtime >/dev/null ; then
POTTIER Francois's avatar
POTTIER Francois committed
10 11 12 13 14
  TIME=gtime
else
  TIME=time
fi

15
# Testing ocamlyacc is optional.
16
test_ocamlyacc=true
17

POTTIER Francois's avatar
POTTIER Francois committed
18
# Make sure Menhir and MenhirLib are up-to-date.
19
./build.sh || exit 1
POTTIER Francois's avatar
POTTIER Francois committed
20

21 22 23
# Remove any stale performance measurements.
rm -f gene/*.time

POTTIER Francois's avatar
POTTIER Francois committed
24
# Build the parser with the code back-end.
25
# Do not link MenhirLib.
POTTIER Francois's avatar
POTTIER Francois committed
26
echo "Building (code)..."
27
make -C $GENE MENHIR="$MENHIR" clean all >/dev/null || exit 1
28 29 30
cp -RH $GENE/gene.native $GENE/gene.code

# Build the parser with the table back-end.
31
# Do link MenhirLib.
32
echo "Building (table)..."
33
make -C $GENE MENHIR="$MENHIR --table" TAGS="-tags 'package(menhirLib)'" clean all >/dev/null || exit 1
34 35 36 37 38
cp -RH $GENE/gene.native $GENE/gene.table

# (Optionally) Build the parser with ocamlyacc.
if $test_ocamlyacc; then
  echo "Building (ocamlyacc)..."
39
  make -C $GENE OCAMLBUILD="ocamlbuild -use-ocamlfind" clean all >/dev/null || exit 1
40 41
  cp -RH $GENE/gene.native $GENE/gene.ocamlyacc
fi
POTTIER Francois's avatar
POTTIER Francois committed
42

43 44
# A loop with several test sizes.

45
for size in 1000000 5000000 10000000 ; do
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
  echo "Test size: $size"

  # Dry run (measures the random generation time).
  echo Dry run:
  $TIME -f "%U" $GENE/gene.code --size $size --dry-run 2> $GENE/dry.time
  cat $GENE/dry.time

  # Run the code back-end.
  echo Code back-end:
  $TIME -f "%U" $GENE/gene.code --size $size > $GENE/code.out 2> $GENE/code.time
  cat $GENE/code.time

  # Run the table back-end.
  echo Table back-end:
  $TIME -f "%U" $GENE/gene.table --size $size > $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

  # (Optionally) Run the ocamlyacc parser.

  if $test_ocamlyacc; then
    echo ocamlyacc:
    $TIME -f "%U" $GENE/gene.ocamlyacc --size $size > $GENE/ocamlyacc.out 2> $GENE/ocamlyacc.time
    cat $GENE/ocamlyacc.time
  fi

  # Compute some statistics.
  ocaml speed.ml

done
85