-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
bench.rb
executable file
·63 lines (53 loc) · 1.31 KB
/
bench.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/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}"])