-
Notifications
You must be signed in to change notification settings - Fork 0
/
timegen.sh
93 lines (88 loc) · 1.77 KB
/
timegen.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
85
86
87
88
89
90
91
92
93
if [ $# -eq 0 ]; then
echo "Usage: $0 --haskell|--python -r ROWS -c COLUMNS -n NTESTS [-o FILE]"
exit 1
fi
CSV_FILE="time.csv"
while [[ $# -gt 0 ]]; do
case $1 in
--haskell)
lang=haskell
shift 1
;;
--python)
lang=python
shift 1
;;
-r|--rows)
if [[ $# -gt 1 && $2 =~ ^[0-9]++$ ]]; then
rows=$2
shift 2
else
echo "Error: --rows requires a numeric value" >&2
exit 1
fi
;;
-c|--cols)
if [[ $# -gt 1 && $2 =~ ^[0-9]+$ ]]; then
cols=$2
shift 2
else
echo "Error: --cols requires a numeric value" >&2
exit 1
fi
;;
-n|--number-of-tests)
if [[ $# -gt 1 && $2 =~ ^[0-9]+$ ]]; then
ntests=$2
shift 2
else
echo "Error: --number-of-tests requires a numeric value" >&2
exit 1
fi
;;
-o|--out)
if [[ $# -gt 1 ]]; then
CSV_FILE=$2
shift 2
else
echo "Error: need a filename" >&2
exit 1
fi
;;
*)
echo "Failed to parse: $1" >&2
exit 1
;;
esac
done
TEST_FILE="r$rows.c$cols.test.csv"
if [ ! -f "$TEST_FILE" ]; then
sh gentestdata.sh $rows $cols $TEST_FILE
fi
# Create CSV header if file doesn't exist
if [ ! -f "$CSV_FILE" ]; then
echo "RealTime,UserTime,SystemTime,Rows,Columns,Language" > $CSV_FILE
fi
case $lang in
haskell)
for ((i=1; i<=ntests; i++)); do
env time -f "%e,%U,%S" cabal exec \
bioboombox knn $TEST_FILE \
2>&1 >/dev/null \
| tr -d '\n' \
>> $CSV_FILE
echo ,$rows,$cols,$lang >> $CSV_FILE
done
;;
python)
for ((i=1; i<=ntests; i++)); do
env time -f "%e,%U,%S" python \
nearestneighbors.py $TEST_FILE \
2>&1 >/dev/null \
| tr -d '\n' \
>> $CSV_FILE
echo ,$rows,$cols,$lang >> $CSV_FILE
done
;;
esac
echo "Time statistics appended to $CSV_FILE"