-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbenchmark.sh
executable file
·51 lines (43 loc) · 1.2 KB
/
benchmark.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
#! /bin/bash
if [ ${#} -lt 1 ] ; then
echo "Specify benchmark subject."
exit 1
fi
subject="${1}"
trials=10
if [ ${#} -eq 2 ] ; then
trials=${2}
fi
timeFormat="time: %E, mem: %M"
bench() {
program="${1}"
benchInvokeCmd=$(sed -e 's/.*BENCH''_INVOKE_CMD://;t;d' ${program})
if [ "x${benchInvokeCmd}" != "x" ] ; then
echo "Testing program: ${program}..."
benchBuildCmd=$(sed -e 's/.*BENCH''_BUILD_CMD://;t;d' ${program})
benchVersionCmd=$(sed -e 's/.*BENCH''_VERSION_CMD://;t;d' ${program})
if [ "x${benchBuildCmd}" != "x" ] ; then
${benchBuildCmd}
fi
cores=$(nproc)
for i in $(seq ${trials}) ; do
core=$((${RANDOM} % ${cores}))
benchResult=$(echo "" | taskset -c ${core} time -f "${timeFormat}" ${benchInvokeCmd} 2>&1 > /dev/null)
echo "${benchResult}"
done
if [ "x${benchVersionCmd}" != "x" ] ; then
version=$(sh -c "${benchVersionCmd}")
echo "program ${program} version: ${version}"
fi
fi
}
if [ -d "${subject}" ] ; then
find "${subject}" \! -path '*/.git*' -a \! -name '*~' -a \! -name '*.swp' -a -type f | while read target ; do
bench ${target}
done
elif [ -f "${subject}" ] ; then
bench ${subject}
else
echo "Benchmark subject does not exist (${subject})."
exit 1
fi