Last active
August 29, 2015 14:04
-
-
Save ascendbruce/abb001a76d9a24e15465 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 "active_support/core_ext/object/blank" | |
TIMES = 1000000 | |
Benchmark.bmbm do |x| | |
x.report("if present? (actually present)") do | |
TIMES.times do | |
if "1".present? | |
end | |
end | |
end | |
x.report("if present? (actually blank)") do | |
TIMES.times do | |
if "".present? | |
end | |
end | |
end | |
x.report("unless blank? (actually present)") do | |
TIMES.times do | |
unless "1".blank? | |
end | |
end | |
end | |
x.report("unless blank? (actually blank)") do | |
TIMES.times do | |
unless "".blank? | |
end | |
end | |
end | |
end | |
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
# Rehearsal 不算入 | |
user system total real | |
unless blank? (actually present) 0.700000 0.000000 0.700000 ( 0.703966) | |
unless blank? (actually blank) 1.390000 0.000000 1.390000 ( 1.399121) | |
if present? (actually present) 0.790000 0.000000 0.790000 ( 0.795483) | |
if present? (actually blank) 1.410000 0.000000 1.410000 ( 1.406053) | |
user system total real | |
unless blank? (actually present) 0.740000 0.000000 0.740000 ( 0.741436) | |
unless blank? (actually blank) 1.400000 0.000000 1.400000 ( 1.407183) | |
if present? (actually present) 0.780000 0.000000 0.780000 ( 0.775220) | |
if present? (actually blank) 1.420000 0.010000 1.430000 ( 1.431337) | |
# if/unless 上下對調 | |
user system total real | |
if present? (actually present) 0.750000 0.000000 0.750000 ( 0.745319) | |
if present? (actually blank) 1.430000 0.000000 1.430000 ( 1.436408) | |
unless blank? (actually present) 0.660000 0.000000 0.660000 ( 0.659880) | |
unless blank? (actually blank) 1.290000 0.000000 1.290000 ( 1.295552) | |
user system total real | |
if present? (actually present) 0.730000 0.010000 0.740000 ( 0.739630) | |
if present? (actually blank) 1.440000 0.000000 1.440000 ( 1.433405) | |
unless blank? (actually present) 0.650000 0.000000 0.650000 ( 0.654705) | |
unless blank? (actually blank) 1.370000 0.000000 1.370000 ( 1.368957) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment