-
Notifications
You must be signed in to change notification settings - Fork 2
/
benches.sh
59 lines (49 loc) · 1.29 KB
/
benches.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
#!/bin/bash
DATE=`date +"%s"`
CURRENT=$DATE.bench
BENCHTIME=5s
BENCHCOUNT=5
if [ $# -eq 1 ]; then
BENCHCOUNT=$1
elif [ $# -eq 2 ]; then
BENCHTIME=$2
fi
if [ -d ".bench" ]
then
echo "Bench directory exists, skipping..."
else
echo "Creating benches directory..."
mkdir .bench
echo "✔ Done"
fi
echo "Running benchmarks. This may take a while..."
go test -bench=. -count=$BENCHCOUNT -run=^@ -benchmem -cpuprofile cpu.prof -memprofile mem.prof -benchtime=$BENCHTIME > .bench/$CURRENT
echo "✔ Done"
cd .bench/
if [ -f "old.bench" ]
then
echo "Unlinking previous benches..."
rm old.bench
echo "✔ Done"
fi
echo "Linking new benches..."
# The previous latest bench becomes the old one
if [ -f "latest.bench" ]
then
ln latest.bench old.bench
rm latest.bench
fi
# The newly created bench file becomes the latest one
ln $CURRENT latest.bench
# If no old.bench, latest and old are the same
if [ -f "old.bench" ]
then
# do nothing
echo "Existing old.bench file found, continuing..."
else
echo "No old.bench file found. Linking latest.bench to old.bench..."
ln latest.bench old.bench
fi
echo "✔ All Done. You can now compare the new and previous benches by running 'make benchcmp'. "
TIME=$((`date +"%s"` - $DATE))
echo "Successfull after $TIME seconds"