Last active
July 22, 2016 03:09
-
-
Save rhearnorth/bc93cef581102bb9ada059491a2cbae9 to your computer and use it in GitHub Desktop.
This file contains 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' | |
[1, nil, 'string', :sym, Class].each do |sample| | |
Benchmark.bmbm do |x| | |
x.report("case .class.name") do | |
100.times do | |
case sample.class.name | |
when 'String' then 'String' | |
when 'Symbol' then 'Symbol' | |
when 'NilClass' then 'NilClass' | |
when 'Class' then 'Class' | |
when 'Fixnum' then 'Fixnum' | |
end | |
end | |
end | |
x.report("implicit") do | |
100.times do | |
case sample | |
when String then 'String' | |
when Symbol then 'Symbol' | |
when NilClass then 'NilClass' | |
when Class then 'Class' | |
when Fixnum then 'Fixnum' | |
end | |
end | |
end | |
end | |
end | |
Rehearsal ---------------------------------------------------- | |
case .class.name 0.000000 0.000000 0.000000 ( 0.000061) | |
implicit 0.000000 0.000000 0.000000 ( 0.000024) | |
------------------------------------------- total: 0.000000sec | |
user system total real | |
case .class.name 0.000000 0.000000 0.000000 ( 0.000028) | |
implicit 0.000000 0.000000 0.000000 ( 0.000027) | |
Rehearsal ---------------------------------------------------- | |
case .class.name 0.000000 0.000000 0.000000 ( 0.000032) | |
implicit 0.000000 0.000000 0.000000 ( 0.000023) | |
------------------------------------------- total: 0.000000sec | |
user system total real | |
case .class.name 0.000000 0.000000 0.000000 ( 0.000037) | |
implicit 0.000000 0.000000 0.000000 ( 0.000029) | |
Rehearsal ---------------------------------------------------- | |
case .class.name 0.000000 0.000000 0.000000 ( 0.000040) | |
implicit 0.000000 0.000000 0.000000 ( 0.000024) | |
------------------------------------------- total: 0.000000sec | |
user system total real | |
case .class.name 0.000000 0.000000 0.000000 ( 0.000028) | |
implicit 0.000000 0.000000 0.000000 ( 0.000025) | |
Rehearsal ---------------------------------------------------- | |
case .class.name 0.000000 0.000000 0.000000 ( 0.000031) | |
implicit 0.000000 0.000000 0.000000 ( 0.000023) | |
------------------------------------------- total: 0.000000sec | |
user system total real | |
case .class.name 0.000000 0.000000 0.000000 ( 0.000027) | |
implicit 0.000000 0.000000 0.000000 ( 0.000023) | |
Rehearsal ---------------------------------------------------- | |
case .class.name 0.000000 0.000000 0.000000 ( 0.000039) | |
implicit 0.000000 0.000000 0.000000 ( 0.000023) | |
------------------------------------------- total: 0.000000sec | |
user system total real | |
case .class.name 0.000000 0.000000 0.000000 ( 0.000046) | |
implicit 0.000000 0.000000 0.000000 ( 0.000028) | |
[Finished in 1.0s] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment