Skip to content

Instantly share code, notes, and snippets.

@sferik sferik/2.4-bench.rb
Created Dec 28, 2016

Embed
What would you like to do?
require 'benchmark/ips'
def class_integer
0.class == Integer
end
def version_gte
RUBY_VERSION >= '2.4'
end
Benchmark.ips do |x|
x.report("0.class == Integer") { class_integer }
x.report("RUBY_VERSION") { version_gte }
x.compare!
end
__END__
Warming up --------------------------------------
0.class == Integer 255.499k i/100ms
RUBY_VERSION 209.773k i/100ms
Calculating -------------------------------------
0.class == Integer 7.971M (± 5.6%) i/s - 39.858M in 5.016829s
RUBY_VERSION 4.997M (± 3.7%) i/s - 25.173M in 5.044146s
Comparison:
0.class == Integer: 7970583.6 i/s
RUBY_VERSION: 4997419.2 i/s - 1.59x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.