Skip to content

Instantly share code, notes, and snippets.

@mikz
Created September 14, 2012 10:38
Show Gist options
  • Save mikz/3721237 to your computer and use it in GitHub Desktop.
Save mikz/3721237 to your computer and use it in GitHub Desktop.
array = 1_000_000.times.map{ rand(0..3) }
Benchmark.bm do |x|
x.report('check') { array.each_slice(2){|a,b| b == 0 ? 0 : a / b } }
x.report('rescue') { array.each_slice(2){|a,b| a / b rescue 0 } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment