Skip to content

Instantly share code, notes, and snippets.

@sferik
Created December 28, 2016 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sferik/ee1fdf549c22abbe69a2ab4753d3da80 to your computer and use it in GitHub Desktop.
Save sferik/ee1fdf549c22abbe69a2ab4753d3da80 to your computer and use it in GitHub Desktop.
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