-
Notifications
You must be signed in to change notification settings - Fork 1
/
runner
executable file
·127 lines (99 loc) · 2.55 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
# show the platform
uname -a
./ruby/versions/ruby-vips.rb
convert --version
# imagescience appears to be broken on ubuntu 19.10, sadly
# ./ruby/versions/image_science.rb
# 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
# much larger than this and im falls over with cache resources exhausted
tile=5
# 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/t.v $tile $tile
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/t.v)
echo " by" $(vipsheader -f height $tmp/t.v) "pixels"
echo making tiff and jpeg derivatives ...
vips copy $tmp/t.v $tmp/t.tif
vips copy $tmp/t.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 a command several times, return the fastest real time
# sleep for two secs between runs to let the system settle -- after a run
# there's a short period of disc chatter we want to avoid
# check that services like tracker are not running
besttime() {
cmd=$*
times=()
for i in {1..5}; do
sleep 2
times+=($($time -f %e $cmd 2>&1))
done
IFS=$'\n' times=($(sort -g <<<"${times[*]}"))
unset IFS
echo $times
}
# find peak RSS
function maxmem() {
prg=$*
m=$($time -f %M $prg 2>&1)
echo -n -e "$(basename $1)\t"
echo $m
}
# run for tif and jpg sources
function benchmark() {
prg=$1
echo -n -e "$(basename $prg)\t"
echo -n -e "$(besttime $prg $tmp/t.tif $tmp/t2.tif)\t"
echo -n -e "$(besttime $prg $tmp/t.jpg $tmp/t2.jpg)\t"
echo
}
# tests we run
programs="\
ruby/ruby-vips.rb \
ruby/rmagick.rb \
image-magick/image-magick \
"
rm -f $tmp/log
for prg in $programs; do
echo -n timing $prg ...
benchmark $prg >> $tmp/log
echo " done"
done
# we can't test all of them for max memory, only ones which don't fork
# subprocesses
programs="\
ruby/ruby-vips.rb \
ruby/rmagick.rb \
"
rm -f $tmp/memlog
for prg in $programs; do
echo -n measuring memuse for $prg ...
maxmem $prg $tmp/t.tif $tmp/t2.tif >> $tmp/memlog
echo " done"
done
echo
echo real time in seconds, fastest of five runs
echo -e "benchmark\ttiff\tjpeg"
sort -g -k 2 $tmp/log
echo
echo peak memory use in bytes
echo -e "benchmark\tpeak RSS"
sort -g -k 2 $tmp/memlog
rm -rf $tmp