Skip to content

Instantly share code, notes, and snippets.

@cespare
Created July 24, 2012 00:19
Show Gist options
  • Save cespare/3167123 to your computer and use it in GitHub Desktop.
Save cespare/3167123 to your computer and use it in GitHub Desktop.
Imagemagick (rmagick) benchmark
# Need to install imagemagick first.
# sudo apt-get install libmagickwand on ubuntu.
# Available on homebrew as well.
require "RMagick"
images = Dir["./*.png"]
start_time = Time.now
iterations = 0
100.times do
# Load the image into rmagick
images.each do |path|
iterations += 1
image = Magick::Image.read(path).first
image.resize_to_fill!(66, 35)
# Ruby GC doesn't necessarily interact well with big binary blogs. Destroy explicitly.
image.destroy!
end
end
elapsed = Time.now - start_time
puts "Avg. #{(elapsed.to_f * 1000.0 / iterations).round(2)} ms / conversion"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment