Sha256: d58fa10f47597dfcc3c2743e0a41e9c65f351e925be4ea380571d074a3a45aed

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

#!/usr/local/bin/ruby -w

require 'benchmark'
require 'rbconfig'
require 'rubygems'
require 'image_science'

max = (ARGV.shift || 100).to_i
ext = ARGV.shift || 'png'
file = "blah_big.#{ext}"

unless File.exist?(file)
  if RbConfig::CONFIG['host_os'] =~ /darwin/i
    puts 'taking screenshot for thumbnailing benchmarks'
    system "screencapture -SC #{file}"
  elsif RbConfig::CONFIG['host_os'] =~ /linux/i
    puts 'taking screenshot for thumbnailing benchmarks'
    system "gnome-screenshot -f #{file}"
  else
    abort "You need to save an image to #{file} since we cannot generate one"
  end
end

if ext != 'png'
  ImageScience.with_image(file.sub(/#{ext}$/, 'png')) { |img| img.save(file) }
end

puts "# of iterations = #{max}"
Benchmark.bm(20) do |x|
  x.report('null_time') { max.times {} }

  x.report('cropped') do
    max.times do
      ImageScience.with_image(file) do |img|
        img.cropped_thumbnail(100) { |thumb| thumb.save("blah_cropped.#{ext}") }
      end
    end
  end

  x.report('proportional') do
    max.times do
      ImageScience.with_image(file) do |img|
        img.thumbnail(100) { |thumb| thumb.save("blah_thumb.#{ext}") }
      end
    end
  end

  x.report('resize') do
    max.times do
      ImageScience.with_image(file) do |img|
        img.resize(200, 200) { |resize| resize.save("blah_resize.#{ext}") }
      end
    end
  end
end

# File.unlink(*Dir["blah*#{ext}"])

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
image_voodoo-0.9.0 samples/bench.rb
image_voodoo-0.8.9 samples/bench.rb