Instantly share code, notes, and snippets.

Embed
What would you like to do?
Benchmark Imlib2 vs ImageMagick
require "rubygems"
require "benchmark"
require "imlib2"
N = (ARGV.shift || 1).to_i
def bench(title)
puts "\nBenchmark: #{title} (#{N} times)"
Benchmark.bm(7, ">total:", ">avg:") do |bm|
results = []
N.times do |i|
results << bm.report(i.to_s) do
yield i
end
end
total = results.inject {|sum, t| sum+=t}
[total, total/N]
end
end
bench("ImageMagick normal") do |i|
`convert -resize 180x120 -quality 90 -strip 1.jpg magick_normal.jpg`
end
bench("ImageMagick hacked") do |i|
`convert -define jpeg:size=180x120 -resize 180x120 -quality 90 -strip 1.jpg magick_hacked.jpg`
end
bench("imlib2") do |i|
img = Imlib2::Image.load("1.jpg")
new_w = 180
new_h = 120
img.crop_scaled!(0, 0, img.w, img.h, new_w, new_h)
img['quality'] = 90
img.save("imlib2.jpg")
end
require "rubygems"
require "benchmark"
require "RMagick"
require "imlib2"
N = (ARGV.shift || 1).to_i
def bench(title)
puts "\nBenchmark: #{title} (#{N} times)"
Benchmark.bm(7, ">total:", ">avg:") do |bm|
results = []
N.times do |i|
results << bm.report(i.to_s) do
yield i
end
end
total = results.inject {|sum, t| sum+=t}
[total, total/N]
end
end
bench("RMagick") do |i|
img = Magick::Image.read("1.jpg").first
img.change_geometry("180") do |cols, rows, x|
x.resize!(cols, rows)
end
img.write("rmagick.jpg")
end
bench("imlib2") do |i|
img = Imlib2::Image.load("1.jpg")
new_w = 180
new_h = ((new_w.to_f / img.w) * img.h).round
img.crop_scaled!(0, 0, img.w, img.h, new_w, new_h)
img.save("imlib2.jpg")
end
@mirakui

This comment has been minimized.

Owner

mirakui commented Jul 24, 2010

Benchmark: RMagick (10 times)
             user     system      total        real
0        1.260000   0.100000   1.360000 (  1.109011)
1        1.270000   0.030000   1.300000 (  1.247094)
2        1.250000   0.030000   1.280000 (  1.127100)
3        1.270000   0.030000   1.300000 (  1.044628)
4        1.250000   0.030000   1.280000 (  1.063168)
5        1.260000   0.030000   1.290000 (  1.059744)
6        1.260000   0.030000   1.290000 (  1.055595)
7        1.250000   0.020000   1.270000 (  1.073271)
8        1.260000   0.030000   1.290000 (  1.050817)
9        1.250000   0.030000   1.280000 (  1.025685)
>total: 12.580000   0.360000  12.940000 ( 10.856113)
>avg:    1.258000   0.036000   1.294000 (  1.085611)

Benchmark: imlib2 (10 times)
             user     system      total        real
0        0.320000   0.050000   0.370000 (  0.543751)
1        0.300000   0.020000   0.320000 (  0.339278)
2        0.310000   0.010000   0.320000 (  0.433248)
3        0.300000   0.020000   0.320000 (  0.348274)
4        0.300000   0.010000   0.310000 (  0.401550)
5        0.310000   0.020000   0.330000 (  0.337580)
6        0.310000   0.010000   0.320000 (  0.354501)
7        0.300000   0.020000   0.320000 (  0.335095)
8        0.300000   0.020000   0.320000 (  0.331282)
9        0.300000   0.010000   0.310000 (  0.355739)
>total:  3.050000   0.190000   3.240000 (  3.780298)
>avg:    0.305000   0.019000   0.324000 (  0.378030)
@mirakui

This comment has been minimized.

Owner

mirakui commented Jan 22, 2011

Benchmark: ImageMagick normal (10 times)
             user     system      total        real
0        0.000000   0.000000   2.580000 (  2.802524)
1        0.000000   0.000000   2.580000 (  2.748471)
2        0.000000   0.000000   2.600000 (  2.666132)
3        0.000000   0.000000   2.580000 (  2.764027)
4        0.000000   0.000000   2.590000 (  2.712320)
5        0.000000   0.000000   2.580000 (  2.697570)
6        0.000000   0.010000   2.620000 (  2.752294)
7        0.000000   0.000000   2.590000 (  2.664938)
8        0.000000   0.000000   2.590000 (  2.838082)
9        0.000000   0.000000   2.590000 (  2.707610)
>total:  0.000000   0.010000  25.900000 ( 27.353968)
>avg:    0.000000   0.001000   2.590000 (  2.735397)

Benchmark: ImageMagick hacked (10 times)
             user     system      total        real
0        0.000000   0.000000   0.220000 (  0.258719)
1        0.000000   0.000000   0.240000 (  0.261905)
2        0.000000   0.000000   0.220000 (  0.273531)
3        0.000000   0.000000   0.230000 (  0.249532)
4        0.000000   0.000000   0.220000 (  0.248117)
5        0.000000   0.000000   0.240000 (  0.302308)
6        0.000000   0.000000   0.220000 (  0.275414)
7        0.000000   0.000000   0.230000 (  0.319016)
8        0.000000   0.010000   0.230000 (  0.298964)
9        0.000000   0.000000   0.240000 (  0.271492)
>total:  0.000000   0.010000   2.290000 (  2.758999)
>avg:    0.000000   0.001000   0.229000 (  0.275900)

Benchmark: imlib2 (10 times)
             user     system      total        real
0        0.600000   0.090000   0.690000 (  0.857749)
1        0.590000   0.040000   0.630000 (  0.741298)
2        0.590000   0.050000   0.640000 (  1.180781)
3        0.590000   0.040000   0.630000 (  0.811014)
4        0.590000   0.040000   0.630000 (  0.944221)
5        0.580000   0.040000   0.620000 (  0.784418)
6        0.590000   0.030000   0.620000 (  0.771053)
7        0.590000   0.040000   0.630000 (  0.839438)
8        0.590000   0.030000   0.620000 (  0.685453)
9        0.580000   0.040000   0.620000 (  0.708727)
>total:  5.890000   0.440000   6.330000 (  8.324152)
>avg:    0.589000   0.044000   0.633000 (  0.832415)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment