Skip to content

Instantly share code, notes, and snippets.

@mtkd
Created December 25, 2015 11:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtkd/c0e40a0d367fd8488b30 to your computer and use it in GitHub Desktop.
Save mtkd/c0e40a0d367fd8488b30 to your computer and use it in GitHub Desktop.
Perf difference between try and safe navigator in Ruby 2.3.0
# Test perf difference between try and safe navigator in Ruby 2.3.0
require 'benchmark'
require 'active_support'
require 'active_support/core_ext/object'
Benchmark.bm do |x|
obj = 0
x.report { 10000.times do; obj.try(:to_s); end; }
x.report { 10000.times do; obj&.to_s; end; }
end
# user system total real
# 0.010000 0.000000 0.010000 ( 0.005675)
# 0.000000 0.000000 0.000000 ( 0.000844)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment