Created
August 2, 2017 09:38
-
-
Save seban/3fbddcdd75c3876e68c9397b8ada7fd0 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' | |
def test_exception | |
raise "test exception" unless true | |
2 + 2 | |
rescue | |
4 | |
end | |
def test_unless | |
unless true | |
2 + 2 | |
else | |
4 | |
end | |
end | |
def test_if | |
if true | |
4 | |
else | |
2 + 2 | |
end | |
end | |
Benchmark.bm do |x| | |
x.report("exception") { 10_000_000.times { test_exception } } | |
x.report("unless") { 10_000_000.times { test_unless } } | |
x.report("if") { 10_000_000.times { test_if }} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thx for this compare :)
maybe a small visual improvements like: