-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.sh
More file actions
43 lines (40 loc) · 748 Bytes
/
lib.sh
File metadata and controls
43 lines (40 loc) · 748 Bytes
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
#!/bin/bash
check_ramdisk() {
if [[ -z "$RAMDISK" ]]; then
echo "Error: RAMDISK is not set" >&2
exit 1
fi
}
check_file() {
file=$1
if [[ ! -s "$file" ]]; then
echo "Error: Missing $file" >&2
exit 1
fi
}
timer() {
if command -v /usr/bin/time >/dev/null 2>&1; then
/usr/bin/time -f "%e %M" bash -c "$@" 2>&1
else
start=$(date +%s.%N)
bash -c "$@"
end=$(date +%s.%N)
awk "BEGIN { print $end - $start }"
fi
}
bench() {
lang=$1
expected=$2
actual=$3
cmd=$4
time=$(timer "$cmd")
diff --strip-trailing-cr $expected $actual > /dev/null
ret=$?
rm $actual
if [[ $ret -eq 0 ]]
then
echo -e "\e[32m[OK]\e[0m $lang $time"
else
echo -e "\e[31m[FAILED]\e[0m $lang $time"
fi
}