This repository was archived by the owner on Feb 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-timeit
More file actions
executable file
·116 lines (99 loc) · 2.96 KB
/
git-timeit
File metadata and controls
executable file
·116 lines (99 loc) · 2.96 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
#
# git-timeit - run a shell command on different Git revisions and measure the elapsed time.
#
# Usage: $0 [-r <num runs>] [-s|--shell] [-f|--file <results.json>] [-o|--output <output.png/.svg>] [-p|--prepare=<preparation shell command>] <Git revision range> <command line>
# If <Git revision range> is "-", a list of revisions is read from stdin. (TODO)
#
# TODO:
# - check that timeit and git are installed
# - describe how to test very first commit as well
baseFileName=./git-timeit-results-$(date +%Y-%m-%dT%H:%M:%S)
prepCmd=
declare -a testCmd
declare -a timeitArgs
resultFile="$baseFileName".json
outputFile="$baseFileName".png
while [[ $# -gt 0 ]]; do
key=$1
case $key in
-h|--help)
echo "Usage: $0 [-r <num runs>] [-s|--shell] [-f|--file <results.json>] [-o|--output <output.png/.svg>] [-p|--prepare=<preparation shell command>] <Git revision range> <command line>"
exit 0
;;
-r)
timeitArgs+=("-r" "$2")
shift
shift
;;
-s|--shell)
timeitArgs+=("-s")
shift
;;
-f|--file)
resultFile=$2
shift
shift
;;
-o|--output)
outputFile=$2
shift
shift
;;
-p)
prepCmd=$2
shift
shift
;;
*)
if [ -z "$gitRevRange" ]; then
gitRevRange=$1
else
testCmd+=("$1")
fi
shift
esac
done
if ! git rev-parse >/dev/null 2>&1; then
echo "Error: this must be run in a Git repository."
exit 1
fi
if ! git diff --no-patch --exit-code ; then
echo "Error: there are unstaged changes."
exit 1
fi
if ! git diff --cached --no-patch --exit-code; then
echo "Error: there are staged but uncommitted changes."
exit 1
fi
if [ -z "$gitRevRange" ]; then
echo "Error: no revision range specified."
exit 1
fi
revisions=$(git rev-list "$gitRevRange" --)
if [ -z "$revisions" ]; then
echo "Error: not a valid revision range: \"$gitRevRange\"."
exit 1
fi
read -d '' -r -a revList <<< "$revisions"
echo "testing ${#revList[@]} revisions"
originalBranch=$(git rev-parse --abbrev-ref HEAD)
# iterate over revisions in reverse order:
for (( idx=${#revList[@]}-1; idx>=0; idx-- )) ; do
rev=${revList[idx]}
echo "checking out revision \"$rev\""
git checkout -q "$rev"
if [ -n "$prepCmd" ]; then
echo "running preparation command: \"$prepCmd\""
bash -c "$prepCmd"
res=$?
if [ $res -ne 0 ]; then
echo "preparation command exited with error code $res - continuing."
fi
fi
echo "running timeit"
revDesc=$(git show -s --pretty=format:"%h %s" "$rev" | cut -c 1-50)
timeit "${timeitArgs[@]}" -m "$revDesc" -f "$resultFile" "${testCmd[@]}"
done
git checkout "$originalBranch"
timeit -f "$resultFile" -o "$outputFile"