Skip to content

Instantly share code, notes, and snippets.

@sandofsky
Created May 6, 2010 07:14
Show Gist options
  • Save sandofsky/391887 to your computer and use it in GitHub Desktop.
Save sandofsky/391887 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'rusage'
require 'pp'
require 'benchmark'
files = Dir['samples/**/*']
command = case ARGV[0]
when 'gd2'
require 'gd2'
lambda do |file|
GD2::Image.import(file).resize(128, 128).export('/dev/null', :format => :jpeg)
end
when 'image_science'
require 'image_science'
lambda do |file|
ImageScience.with_image(file) do |img|
img.thumbnail(128) do |resized|
resized.save('/dev/null')
end
end
end
when 'mini_magick'
require 'mini_magick'
lambda do |file|
image = MiniMagick::Image.from_file(file)
image.resize('128x128')
image.write('/dev/null')
end
end
memory_record = [Process.rusage.maxrss]
time = Benchmark.measure do
files.each_with_index do |file, i|
command.call(file)
memory_record << Process.rusage.maxrss if i % 20 == 0
end
end
puts "Time: #{time}"
puts "Memory: #{memory_record.join(', ')}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment