Created — forked from ngauthier/readme.md

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View benchmark.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
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
View benchmark.rb

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

is very very slow

View benchmark.rb
1 2 3 4
~ $ 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.