Created
June 30, 2010 09:24
-
-
Save jarmo/458454 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
require "rmagick" | |
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib')) | |
require 'win32/screenshot' | |
t = "Internet Explorer" | |
Benchmark.bmbm do |x| | |
x.report("no file") {50.times {Win32::Screenshot.window(t, 0) {}}} | |
x.report("bmp") do | |
50.times do | |
Win32::Screenshot.window(t, 0) do |w, h, b| | |
File.open("picture.bmp", "wb") {|f| f.puts b} | |
end | |
end | |
end | |
x.report("png") do | |
50.times do | |
Win32::Screenshot.window(t, 0) do |w, h, b| | |
img = Magick::Image.from_blob(b) | |
png = img[0].to_blob {self.format = 'PNG'} | |
File.open("picture.png", "wb") do |f| | |
f.puts png | |
end | |
end | |
end | |
end | |
x.report("rect") do | |
50.times do | |
Win32::Screenshot.window_rect(t, 0, 0, 100, 200, 0) do |w, h, b| | |
img = Magick::Image.from_blob(b) | |
png = img[0].to_blob {self.format = 'PNG'} | |
File.open("picture-rect.png", "wb") do |f| | |
f.puts png | |
end | |
end | |
end | |
end | |
x.report("crop") do | |
50.times do | |
Win32::Screenshot.window(t, 0) do |w, h, b| | |
img = Magick::Image.from_blob(b) | |
img[0].crop!(0, 0, 100, 200) | |
png = img[0].to_blob {self.format = 'PNG'} | |
File.open("picture-crop.png", "wb") do |f| | |
f.puts png | |
end | |
end | |
end | |
end | |
end | |
=begin | |
output: | |
Rehearsal ------------------------------------------- | |
no file 1.451000 1.014000 2.465000 ( 3.123179) | |
bmp 1.529000 1.232000 2.761000 ( 3.739214) | |
png 11.372000 1.389000 12.761000 ( 14.965856) | |
rect 0.578000 0.078000 0.656000 ( 0.847049) | |
crop 2.262000 1.185000 3.447000 ( 4.491257) | |
--------------------------------- total: 22.090000sec | |
user system total real | |
no file 1.404000 0.874000 2.278000 ( 2.918166) | |
bmp 1.404000 1.154000 2.558000 ( 3.240186) | |
png 11.248000 1.326000 12.574000 ( 14.314819) | |
rect 0.452000 0.156000 0.608000 ( 0.757044) | |
crop 2.246000 1.139000 3.385000 ( 4.172238) | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment