Created
December 28, 2016 18:55
-
-
Save sferik/ee1fdf549c22abbe69a2ab4753d3da80 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/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