Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: 2012.09.15
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 124 lines (100 sloc) 2.408 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 117 118 119 120 121 122 123
#!/bin/bash

# show the platform
uname -a
./ruby/versions/ruby-vips.rb
convert --version
tifftopnm --version
./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
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 im_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" `header -f width $tmp/t.v`
echo " by" `header -f height $tmp/t.v` "pixels"

echo making tiff and jpeg derivatives ...
vips im_copy $tmp/t.v $tmp/t.tif
vips im_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 three times, take the fastest real time
function bestof3() {
  prg=$*

  t1=$($time -f %e $prg 2>&1)
  t2=$($time -f %e $prg 2>&1)
  t3=$($time -f %e $prg 2>&1)

  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)

  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 "$(bestof3 $prg $tmp/t.tif $tmp/t2.tif)\t"
  echo -n -e "$(bestof3 $prg $tmp/t.jpg $tmp/t2.jpg)\t"

  echo
}

# tests we run
programs="\
ruby/ruby-vips.rb \
ruby/rmagick.rb \
image-magick/image-magick \
ruby/image_sci.rb \
netpbm/netpbm.sh \
"

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 \
ruby/image_sci.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 three runs
echo -e "benchmark\ttiff\tjpeg"
sort -g -k 2 $tmp/log

echo
echo peak memory use in kilobytes
echo -e "benchmark\tpeak RSS"
sort -g -k 2 $tmp/memlog

rm -rf $tmp
Something went wrong with that request. Please try again.