blob: c6187ad2acb488d117772115e12dbfb8b52f6130 (
plain) (
blame)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
scriptDir="$(cd "$(dirname "$0")"; pwd)"
source "$scriptDir/radar-base.sh"
cd_to_tmp() {
tmpfile="/tmp/git-prompt-tests-$(time_now)$1"
mkdir -p "$tmpfile"
cd "$tmpfile"
}
rm_tmp() {
cd $scriptDir
rm -rf /tmp/git-prompt-tests*
}
report() {
arr=( "$@" )
printf '%s\n' "${arr[@]}" | sort -n | awk '
function colored(s) {
OFMT="%2.3fs";
OFS="";
ORS="";
if( s > 0.2 ) {
print "\033[1;31m", s, "\033[0m"
} else if( s > 0.1 ) {
print "\033[1;33m", s, "\033[0m"
} else {
print "\033[1;32m", s, "\033[0m"
}
OFS="\t";
ORS="\n";
}
BEGIN {
c = 0;
sum = 0;
}
$1 ~ /^[0-9]*(\.[0-9]*)?$/ {
a[c++] = $1;
sum += $1;
}
END {
min = a[0] + 0;
max = a[c-1] + 0;
ave = sum / c;
if( (c % 2) == 1 ) {
median = a[ int(c/2) ];
} else {
median = ( a[c/2] + a[c/2-1] ) / 2;
}
OFS="\t";
OFMT="%2.3fs";
print c, colored(ave), colored(median), colored(min), colored(max);
}
'
}
table_headers() {
printf " Count\tMean\tMedian\tMin\tMax\n"
}
profile () {
cmd="$2"
for (( i = 0; i < 100; i++ )); do
start=$(gdate +%s.%N)
eval $cmd > /dev/null
duration=$(echo "$(gdate +%s.%N) - $start" | bc)
timings[$i]=$duration
done
printf '%-25s' "$1"
report "${timings[@]}"
}
test_empty_repo() {
cd_to_tmp
git init --quiet
table_headers
profile "prompt.zsh" "/.$scriptDir/prompt.zsh"
profile "prompt.bash" "/.$scriptDir/prompt.bash"
rm_tmp
}
test_lots_of_file_changes() {
cd_to_tmp
git init --quiet
table_headers
profile "no changes zsh" "/.$scriptDir/prompt.zsh"
profile "no changes bash" "/.$scriptDir/prompt.bash"
for (( i = 0; i < 100; i++ )); do
touch foo$i
done
profile "100 untracked zsh" "/.$scriptDir/prompt.zsh"
profile "100 untracked bash" "/.$scriptDir/prompt.bash"
for (( i = 0; i < 100; i++ )); do
touch bar$i
git add bar$i
done
profile "100 added zsh" "/.$scriptDir/prompt.zsh"
profile "100 added bash" "/.$scriptDir/prompt.bash"
for (( i = 0; i < 100; i++ )); do
echo "bar$i" > bar$i
done
profile "100 modify zsh" "/.$scriptDir/prompt.zsh"
profile "100 modify bash" "/.$scriptDir/prompt.bash"
rm_tmp
}
test_commits_local_and_remote_ahead() {
cd_to_tmp "remote"
git init --quiet
touch README
git add .
git commit -m "initial commit" --quiet
remoteLocation="$(pwd)"
cd_to_tmp "new"
git init --quiet
git remote add origin $remoteLocation
git fetch origin --quiet
git checkout master --quiet
git checkout -b foo --quiet
git push --quiet -u origin foo >/dev/null
table_headers
profile "0 commits zsh" "/.$scriptDir/prompt.zsh"
profile "0 commits bash" "/.$scriptDir/prompt.bash"
for (( i = 0; i < 100; i++ )); do
echo "foo$i" >> foo
git add .
git commit -m "foo $i" --quiet
done
profile "100 local zsh" "/.$scriptDir/prompt.zsh"
profile "100 local bash" "/.$scriptDir/prompt.bash"
git push --quiet
profile "100 remote zsh" "/.$scriptDir/prompt.zsh"
profile "100 remote bash" "/.$scriptDir/prompt.bash"
rm_tmp
}
test_large_repo() {
cd_to_tmp
git clone https://github.com/Homebrew/homebrew --quiet
cd homebrew
table_headers
profile "prompt.zsh" "/.$scriptDir/prompt.zsh"
profile "prompt.bash" "/.$scriptDir/prompt.bash"
rm_tmp
}
test_lots_of_submodules() {
cd_to_tmp
git clone https://github.com/michaeldfallen/dotfiles --quiet
cd dotfiles
git submodule update --init --quiet
table_headers
profile "prompt.zsh" "/.$scriptDir/prompt.zsh"
profile "prompt.bash" "/.$scriptDir/prompt.bash"
rm_tmp
}
. ./shunit/shunit2
|