Sha256: d01c965b94b6a1536b98e7681078ecb106464be4784213d388a848d64fa55aa2

Contents?: true

Size: 1.31 KB

Versions: 33

Compression:

Stored size: 1.31 KB

Contents

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

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

max = (ARGV.shift || 100).to_i
ext = ARGV.shift || "png"

file = "blah_big.#{ext}"

if RUBY_PLATFORM =~ /darwin/ then
  # how fucking cool is this???
  puts "taking screenshot for thumbnailing benchmarks"
  system "screencapture -SC #{file}"
else
  abort "You need to plonk down #{file} or buy a mac"
end unless test ?f, "#{file}"

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

puts "# of iterations = #{max}"
Benchmark::bm(20) do |x|
  x.report("null_time") {
    for i in 0..max do
      # do nothing
    end
  }

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

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

  x.report("resize") {
    for i in 0..max do
      ImageScience.with_image(file) do |img|
        img.resize(200, 200) do |resize|
          resize.save("blah_resize.#{ext}")
        end
      end
    end
  }
end

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

Version data entries

33 entries across 33 versions & 9 rubygems

Version Path
image_science-1.3.2 bench.rb
image_science-1.3.1 bench.rb
image_science-1.3.0 bench.rb
carlosnz-image_science-1.1.3.1 bench.rb
carlosnz-image_science-1.1.3 bench.rb
scambra-image_science-1.2.0 bench.rb
stateless-systems-image_science-1.2.1 bench.rb
tdd-image_science-1.2.1 bench.rb
tdd-image_science-1.2.2 bench.rb
image_science-1.2.6 bench.rb
image_science-1.2.5 bench.rb
image_science-1.2.4 bench.rb
jemmyw-image_science-1.3.3.0.Jemmyw bench.rb
jemmyw-image_science-1.3.2.1.Jemmyw bench.rb
jemmyw-image_science-1.3.2.1.Asynchrony bench.rb
tlconnor-image_science-1.3.2.1.Asynchrony bench.rb
image_science-1.2.3 bench.rb
image_science-1.2.2 bench.rb
g1nn13-image_science-1.2.10 bench.rb
hcatlin-image_science-1.2.2 bench.rb