Last active
September 17, 2015 22:21
-
-
Save IceDragon200/35ecad7c6ed1d8c599e8 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' | |
Benchmark.bmbm do |x| | |
a, b = 1, 0 | |
n = 1_000_000 | |
x.report('Catching a DivisionByZero') { n.times { a / b rescue nil } } | |
x.report('Checking if dividend is 0') { n.times { b == 0 ? nil : a / b } } | |
end |
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
Rehearsal ------------------------------------------------------------- | |
Catching a DivisionByZero 3.250000 0.000000 3.250000 ( 3.268005) | |
Checking if dividend is 0 0.080000 0.000000 0.080000 ( 0.076027) | |
---------------------------------------------------- total: 3.330000sec | |
user system total real | |
Catching a DivisionByZero 2.990000 0.000000 2.990000 ( 3.002021) | |
Checking if dividend is 0 0.080000 0.000000 0.080000 ( 0.079421) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment