Created
July 24, 2010 04:29
-
-
Save mirakui/488401 to your computer and use it in GitHub Desktop.
Benchmark Imlib2 vs ImageMagick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Author
mirakui
commented
Jul 24, 2010
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