Skip to content

Instantly share code, notes, and snippets.

@zachpendleton
Created August 13, 2013 16:07
Show Gist options
  • Select an option

  • Save zachpendleton/6222743 to your computer and use it in GitHub Desktop.

Select an option

Save zachpendleton/6222743 to your computer and use it in GitHub Desktop.
Rescuing in Ruby sucks
require 'benchmark'
Benchmark.benchmark do |x|
x.report {
100_000.times { nil.to_sym rescue :or }
}
x.report {
100_000.times { nil.try(:to_sym) || :or
}
x.report {
100_000.times { nil ? nil.to_sym : :or }
}
end
# 6.120000 0.050000 6.170000 (6.175324)
# 0.020000 0.000000 0.020000 (0.016220)
# 0.000000 0.000000 0.000000 (0.005985)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment