Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?

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