-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner
executable file
·105 lines (84 loc) · 1.95 KB
/
runner
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
#!/bin/bash
# how large an image do you want to process?
# sample2.v is 290x442 pixels ... replicate this many times horizontally and
# vertically to get a highres image for the benchmark
tile=10
# make a dir for our temp files
tmp=tmp
rm -rf $tmp
mkdir $tmp
# sample image is here
sample=images/sample2.v
echo building test image ...
echo "tile=$tile"
vips replicate $sample $tmp/t1.v 18 12
vips crop $tmp/t1.v $tmp/t2.v 0 0 5000 5000
if [ $? != 0 ]; then
echo "build of test image failed -- out of disc space?"
exit 1
fi
echo -n "test image is" $(vipsheader -f width $tmp/t2.v)
echo " by" $(vipsheader -f height $tmp/t2.v) "pixels"
echo make jpeg derivatives ...
vips copy $tmp/t2.v $tmp/t.jpg
# we want to use the time program, not the one built into the shell
time=$(which time)
if [ $? != 0 ]; then
echo "unable to locate 'time' program"
exit 1
fi
# run three times, take the fastest real time
function bestof3() {
prg=$*
t1=$($time -f %e $prg 2>&1 >/dev/null)
t2=$($time -f %e $prg 2>&1 >/dev/null)
t3=$($time -f %e $prg 2>&1 >/dev/null)
if [[ $t2 < $t1 ]]; then
t1=$t2
fi
if [[ $t3 < $t1 ]]; then
t1=$t3
fi
echo $t1
}
# find peak RSS
function maxmem() {
prg=$*
m=$($time -f %M $prg 2>&1 >/dev/null)
echo -n -e "$(basename $1)\t"
echo $m
}
# run for jpg
function benchmark() {
prg=$1
echo -n -e "$(basename $prg)\t"
echo -n -e "$(bestof3 $prg $tmp/t.jpg $tmp/t2.jpg)\t"
echo
}
# tests we run
programs="\
./vips.php
./imagick.php
./gd.php
"
rm -f $tmp/log
for prg in $programs; do
echo -n timing $prg ...
benchmark $prg >> $tmp/log
echo " done"
done
rm -f $tmp/memlog
for prg in $programs; do
echo -n measuring memuse for $prg ...
maxmem $prg $tmp/t.jpg $tmp/t2.jpg >> $tmp/memlog
echo " done"
done
echo
echo real time in seconds, fastest of three runs
echo -e "benchmark\tjpeg"
sort -g -k 2 $tmp/log
echo
echo peak memory use in KB
echo -e "benchmark\tpeak RSS"
sort -g -k 2 $tmp/memlog
rm -rf $tmp