-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathperformance-test.sh
executable file
·358 lines (318 loc) · 10.1 KB
/
performance-test.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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
#!/bin/bash
set -e
# Due to system integrity protection, macOS requires us to use a copy of date
# if we want it to work with faketime.
DATE="$( command -v date )"
if [ "$( uname -s )" = "Darwin" ]; then
TEMP_DATE=$( mktemp )
cp "${DATE}" "${TEMP_DATE}"
chmod +x "${TEMP_DATE}"
DATE="${TEMP_DATE}"
function cleanup {
rm -fr "${DATE}"
}
trap cleanup EXIT
fi
THREE_HOURS_BEFORE=$( faketime '3 hours ago' "${DATE}" "+%Y%m%dT%H0000" )
TWO_HOURS_BEFORE=$( faketime '2 hours ago' "${DATE}" "+%Y%m%dT%H0000" )
ONE_HOUR_BEFORE=$( faketime '1 hours ago' "${DATE}" "+%Y%m%dT%H0000" )
TIMEW_BIN="${BASH_SOURCE[0]%/*}/../src/timew"
[[ -x "${TIMEW_BIN}" ]] || exit 1
function test_performance_annotate()
{
# setup
${TIMEW_BIN} track "${TWO_HOURS_BEFORE}" - "${ONE_HOUR_BEFORE}" TEST >/dev/null
# test
( ( time -p (
${TIMEW_BIN} annotate @1 ANNOTATION >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
# cleanup
${TIMEW_BIN} delete @1 >/dev/null
}
function test_performance_cancel()
{
# setup
${TIMEW_BIN} start "${TWO_HOURS_BEFORE}" TEST >/dev/null
# test
( ( time -p (
${TIMEW_BIN} cancel >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
}
function test_performance_continue()
{
# setup
${TIMEW_BIN} track "${TWO_HOURS_BEFORE}" - "${ONE_HOUR_BEFORE}" TEST >/dev/null
# test
( ( time -p (
${TIMEW_BIN} continue @1 >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
# cleanup
${TIMEW_BIN} cancel >/dev/null
${TIMEW_BIN} delete @1 >/dev/null
}
function test_performance_day()
{
# setup
${TIMEW_BIN} track "${TWO_HOURS_BEFORE}" - "${ONE_HOUR_BEFORE}" TEST >/dev/null
# test
( ( time -p (
${TIMEW_BIN} day >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
# cleanup
${TIMEW_BIN} delete @1 >/dev/null
}
function test_performance_delete()
{
# setup
${TIMEW_BIN} track "${TWO_HOURS_BEFORE}" - "${ONE_HOUR_BEFORE}" TEST >/dev/null
# test
( ( time -p (
${TIMEW_BIN} delete @1 >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
}
function test_performance_export()
{
# test
( ( time -p (
${TIMEW_BIN} export >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
}
function test_performance_gaps()
{
# test
( ( time -p (
${TIMEW_BIN} gaps >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
}
function test_performance_get()
{
# test
( ( time -p (
${TIMEW_BIN} get dom.active >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
}
function test_performance_join()
{
# setup
${TIMEW_BIN} track "${THREE_HOURS_BEFORE}" - "${TWO_HOURS_BEFORE}" TEST >/dev/null
${TIMEW_BIN} track "${TWO_HOURS_BEFORE}" - "${ONE_HOUR_BEFORE}" TEST >/dev/null
# test
( ( time -p (
${TIMEW_BIN} join @1 @2 >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
# cleanup
${TIMEW_BIN} delete @1 >/dev/null
}
function test_performance_lengthen()
{
# setup
${TIMEW_BIN} track "${THREE_HOURS_BEFORE}" - "${TWO_HOURS_BEFORE}" TEST >/dev/null
# test
( ( time -p (
${TIMEW_BIN} lengthen @1 30min >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
# cleanup
${TIMEW_BIN} delete @1 >/dev/null
}
function test_performance_month()
{
# setup
${TIMEW_BIN} track "${TWO_HOURS_BEFORE}" - "${ONE_HOUR_BEFORE}" TEST >/dev/null
# test
( ( time -p (
${TIMEW_BIN} month >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
# cleanup
${TIMEW_BIN} delete @1 >/dev/null
}
function test_performance_modify-end()
{
# setup
${TIMEW_BIN} track "${THREE_HOURS_BEFORE}" - "${TWO_HOURS_BEFORE}" TEST >/dev/null
# test
( ( time -p (
${TIMEW_BIN} modify end @1 "${ONE_HOUR_BEFORE}" >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
# cleanup
${TIMEW_BIN} delete @1 >/dev/null
}
function test_performance_modify-start()
{
# setup
${TIMEW_BIN} track "${TWO_HOURS_BEFORE}" - "${ONE_HOUR_BEFORE}" TEST >/dev/null
# test
( ( time -p (
${TIMEW_BIN} modify start @1 "${THREE_HOURS_BEFORE}" >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
# cleanup
${TIMEW_BIN} delete @1 >/dev/null
}
function test_performance_move()
{
# setup
${TIMEW_BIN} track "${THREE_HOURS_BEFORE}" - "${TWO_HOURS_BEFORE}" TEST >/dev/null
# test
( ( time -p (
${TIMEW_BIN} move @1 "${TWO_HOURS_BEFORE}" >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
# cleanup
${TIMEW_BIN} delete @1 >/dev/null
}
function test_performance_resize()
{
# setup
${TIMEW_BIN} track "${TWO_HOURS_BEFORE}" - "${ONE_HOUR_BEFORE}" TEST >/dev/null
# test
( ( time -p (
${TIMEW_BIN} resize @1 30min >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
# cleanup
${TIMEW_BIN} delete @1 >/dev/null
}
function test_performance_shorten()
{
# setup
${TIMEW_BIN} track "${TWO_HOURS_BEFORE}" - "${ONE_HOUR_BEFORE}" TEST >/dev/null
# test
( ( time -p (
${TIMEW_BIN} shorten @1 30min >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
# cleanup
${TIMEW_BIN} delete @1 >/dev/null
}
function test_performance_split()
{
# setup
${TIMEW_BIN} track "${TWO_HOURS_BEFORE}" - "${ONE_HOUR_BEFORE}" TEST >/dev/null
# test
( ( time -p (
${TIMEW_BIN} split @1 >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
# cleanup
${TIMEW_BIN} delete @1 @2 >/dev/null
}
function test_performance_start()
{
# test
( ( time -p (
${TIMEW_BIN} start "${TWO_HOURS_BEFORE}" TEST >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
# cleanup
${TIMEW_BIN} cancel >/dev/null
}
function test_performance_stop()
{
# setup
${TIMEW_BIN} start "${TWO_HOURS_BEFORE}" TEST >/dev/null
# test
( ( time -p (
${TIMEW_BIN} stop "${ONE_HOUR_BEFORE}" TEST >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
# cleanup
${TIMEW_BIN} delete @1 >/dev/null
}
function test_performance_summary()
{
# test
( ( time -p (
${TIMEW_BIN} summary >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
}
function test_performance_tag()
{
# setup
${TIMEW_BIN} track "${TWO_HOURS_BEFORE}" - "${ONE_HOUR_BEFORE}" TEST >/dev/null
# test
( ( time -p (
${TIMEW_BIN} tag @1 TAG >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
# cleanup
${TIMEW_BIN} delete @1 >/dev/null
}
function test_performance_tags()
{
# test
( ( time -p (
${TIMEW_BIN} tags >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
}
function test_performance_track()
{
# test
( ( time -p (
${TIMEW_BIN} track "${TWO_HOURS_BEFORE}" - "${ONE_HOUR_BEFORE}" TEST >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
# cleanup
${TIMEW_BIN} delete @1 >/dev/null
}
function test_performance_undo()
{
# setup
${TIMEW_BIN} track "${TWO_HOURS_BEFORE}" - "${ONE_HOUR_BEFORE}" TEST >/dev/null
# test
( ( time -p (
${TIMEW_BIN} undo >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
# cleanup
}
function test_performance_untag()
{
# setup
${TIMEW_BIN} track "${TWO_HOURS_BEFORE}" - "${ONE_HOUR_BEFORE}" TEST >/dev/null
# test
( ( time -p (
${TIMEW_BIN} untag @1 TEST >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
# cleanup
${TIMEW_BIN} delete @1 >/dev/null
}
function test_performance_week()
{
# setup
${TIMEW_BIN} track "${TWO_HOURS_BEFORE}" - "${ONE_HOUR_BEFORE}" TEST >/dev/null
# test
( ( time -p (
${TIMEW_BIN} week >/dev/null
) 2>&1 >/dev/null ) | awk '{a[NR]=$2}; END {for(i=1;i<=3;i++){printf "%s\t",a[i]}}')
# cleanup
${TIMEW_BIN} delete @1 >/dev/null
}
OUTPUT_DIR="${1-/tmp/timew-performance}"
export TIMEWARRIORDB=/tmp/timewarriordb
mkdir -p ${TIMEWARRIORDB}/data
rm -f ${TIMEWARRIORDB}/data/*.data
:> ${TIMEWARRIORDB}/timewarrior.cfg
mkdir -p "${OUTPUT_DIR}"
rm -rf "${OUTPUT_DIR:?}"/*
TIMEW_COMMANDS="annotate cancel continue day delete export gaps get join lengthen modify-end modify-start month move resize shorten split start stop summary tag tags track undo untag week"
# Write headers
for timew_cmd in ${TIMEW_COMMANDS} ; do
echo -e "#Performance ${timew_cmd}" > "${OUTPUT_DIR}/timew-${timew_cmd}-performance.log"
echo -e "#TAG\tENTRIES\tREAL\tUSER\tSYS" >> "${OUTPUT_DIR}/timew-${timew_cmd}-performance.log"
done
for step in $( seq 0 20 ) ; do
YEAR_MONTH="$( faketime "${step} months ago" "${DATE}" "+%Y-%m" )"
if [[ "${step}" -gt 0 ]] ; then
year=${YEAR_MONTH%-*}
month=${YEAR_MONTH#*-}
# Increase database by 100 entries
for day in $(seq -w 1 25) ; do
{
echo "inc ${year}${month}${day}T040000Z - ${year}${month}${day}T050000Z # FOO"
echo "inc ${year}${month}${day}T073000Z - ${year}${month}${day}T113000Z # BAR"
echo "inc ${year}${month}${day}T163000Z - ${year}${month}${day}T183000Z # BAZ"
echo "inc ${year}${month}${day}T193000Z - ${year}${month}${day}T203000Z # FOO BAR"
} >> "${TIMEWARRIORDB}/data/${year}-${month}.data"
done
ENTRIES=$( wc -l /tmp/timewarriordb/data/????-??.data | awk '{a=$1} ; END {printf "%s",a}' )
fi
echo -en "Testing with ${ENTRIES-0} entries...\r"
# Run performance tests
for timew_cmd in ${TIMEW_COMMANDS} ; do
{
echo -en "${YEAR_MONTH}\t${ENTRIES-0}\t"
"test_performance_${timew_cmd}"
echo ""
} >> "${OUTPUT_DIR}/timew-${timew_cmd}-performance.log"
done
done