Import Upstream version 20180207
[hcoop/debian/mlton.git] / benchmark / update-counts.sh
CommitLineData
7f918cf1
CE
1#!/usr/bin/env bash
2
3# set -e
4
5die () {
6 echo "$1" >&2
7 exit 1
8}
9
10if $(which gtime) --version >/dev/null 2>&1; then
11 time=$(which gtime)
12elif $(which gnutime) --version >/dev/null 2>&1; then
13 time=$(which gnutime)
14elif $(which time) --version 2>&1 | grep -q GNU; then
15 time=$(which time)
16else
17 die 'Can'\''t find GNU time'
18fi
19
20
21minTime="75.0"
22
23bench="string-concat vector-concat"
24
25cd tests
26for prog in $bench; do
27 case "$prog" in
28 "fxp")
29 continue ;;
30 esac
31
32 ( cat $prog.sml ; echo "val _ = Main.doit (valOf (Int.fromString (hd (CommandLine.arguments ()))))" ) > $prog.main.sml
33 mlton -output $prog $prog.main.sml 1>/dev/null 2>/dev/null
34
35 n=0
36 t=0
37
38 while [ "$(echo "$t < $minTime" | bc)" = "1" ]; do
39 if [ $n -eq 0 ]; then
40 n=1
41 m=1
42 k=1
43 elif [ $n -lt $m ]; then
44 n=$(($n+$k))
45 else
46 m=$((2*$m))
47 if [ $m -lt 8 ]; then
48 n=$m
49 else
50 k=$(( ($m-$n) / 2 ))
51 n=$(($n+$k))
52 fi
53 fi
54 $time -o $prog.time --format "%U + %S" ./$prog $n 1>/dev/null 2>/dev/null
55 t=$(cat $prog.time | grep -v "Command exited" | bc)
56 s=$(grep "Command exited" $prog.time)
57 if [ ! -z "$s" ]; then
58 s="; $s "
59 break
60 fi
61 done
62
63 echo "(\"$prog\", $n):: (* $t sec $s*)"
64
65 rm $prog $prog.main.sml $prog.time
66
67done