Skip to content

Instantly share code, notes, and snippets.

@kke
Created November 15, 2012 20:55
Show Gist options
  • Select an option

  • Save kke/4081209 to your computer and use it in GitHub Desktop.

Select an option

Save kke/4081209 to your computer and use it in GitHub Desktop.
require 'benchmark'
Benchmark.bm do |x|
test = ["test", 1]
x.report(" rescue") { 100000.times { test.collect{|x| x.strip! rescue nil} } }
test = ["test", "test"]
x.report("no rescue") { 100000.times { test.collect{|x| x.strip!} } }
test = ["test", 1]
x.report(" respond") { 100000.times { test.collect{|x| x.strip! if x.respond_to?(:strip!)} } }
end
user system total real
rescue 1.590000 0.020000 1.610000 ( 1.613629)
no rescue 0.070000 0.000000 0.070000 ( 0.060558)
respond 0.100000 0.000000 0.100000 ( 0.180400)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment