Created
September 6, 2018 07:30
-
-
Save kenchan/09e4dfabbbf9e68a5bcfe88fd2f4d5f6 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/ips' | |
Benchmark.ips do |x| | |
x.report("if") do |i| | |
if i % 5 == 0 | |
i | |
end | |
end | |
x.report("raise") do |i| | |
begin | |
raise unless i % 5 == 0 | |
rescue | |
i | |
end | |
end | |
x.compare! | |
end |
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
Warming up -------------------------------------- | |
if 319.284k i/100ms | |
raise 69.463k i/100ms | |
Calculating ------------------------------------- | |
if 317.735B (± 6.4%) i/s - 831.988B | |
raise 65.204B (±20.1%) i/s - 183.890B | |
Comparison: | |
if: 317735485266.5 i/s | |
raise: 65203928436.3 i/s - 4.87x slower |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment