| 1 | #!/bin/sh |
| 2 | # The kernels: each raz program here, which says check off, against its |
| 3 | # twin in Pascal, built by FPC -O2; each run five times, the fastest |
| 4 | # kept. Run from the directory above test/: |
| 5 | # test/bench/run.sh [compiler] |
| 6 | raz=${1:-./raz} |
| 7 | out=build/bench |
| 8 | mkdir -p $out |
| 9 | |
| 10 | best() { # best program: the fewest milliseconds of five runs |
| 11 | b=0 |
| 12 | for i in 1 2 3 4 5; do |
| 13 | s=$(sh test/nanos.sh); $1 > /dev/null; e=$(sh test/nanos.sh) |
| 14 | t=$(( (e - s) / 1000000 )) |
| 15 | if [ $b = 0 ] || [ $t -lt $b ]; then b=$t; fi |
| 16 | done |
| 17 | echo $b |
| 18 | } |
| 19 | |
| 20 | for f in test/bench/*.raz; do |
| 21 | n=$(basename $f .raz) |
| 22 | $raz -o $out/$n $f || exit 1 |
| 23 | fpc -O2 -v0 -FE$out -o$out/$n.fpc test/bench/$(echo $n | tr A-Z a-z).pas > /dev/null || exit 1 |
| 24 | if [ "$($out/$n)" != "$($out/$n.fpc)" ]; then echo "$n: the two print differently"; exit 1; fi |
| 25 | r=$(best $out/$n); p=$(best $out/$n.fpc) |
| 26 | echo "$n $r $p" | awk '{ printf "%-10s raz %5d ms fpc -O2 %5d ms %.2f times\n", $1, $2, $3, $2 / $3 }' |
| 27 | done |