Skip to content

@bcardarella /benchmark.rb forked from ngauthier/readme.md
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Using Exceptions to manage control flow in Rails Controllers...

is very very slow

require 'benchmark'
def ifelse
if true
1
else
2
end
end
def raiserescue
begin
raise
rescue
2
end
end
Benchmark.bm do |x|
x.report("if/else ") { 10_000.times { ifelse } }
x.report("raise/rescue") { 10_000.times { raiserescue } }
end
~ $ ruby benchmark.rb
user system total real
if/else 0.000000 0.000000 0.000000 ( 0.000985)
raise/rescue 0.100000 0.000000 0.100000 ( 0.102185)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.