Skip to content

Instantly share code, notes, and snippets.

@koshigoe
Created July 8, 2015 06:40
Show Gist options
  • Select an option

  • Save koshigoe/158b0d70353c93cf1214 to your computer and use it in GitHub Desktop.

Select an option

Save koshigoe/158b0d70353c93cf1214 to your computer and use it in GitHub Desktop.
画像100%リサイズを mini_magick と convert で比較
require 'benchmark'
require 'mini_magick'
require 'open3'
n = 100
Benchmark.bm(22) do |x|
x.report("mini_magic") do
n.times do
blob = File.open('sample.jpg')
image = MiniMagick::Image.read(blob)
image.resize "100%"
end
end
x.report("convert") do
n.times do
Open3.popen3('convert -resize 100% sample.jpg -') do |stdin, stdout, stderr, wait_thr|
stdin.close
output = stdout.read
end
end
end
end
$ ruby bench-image-resize.rb
user system total real
mini_magic 0.090000 0.190000 2.300000 ( 3.258090)
convert 0.040000 0.090000 1.560000 ( 1.922639)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment