Created
January 18, 2011 00:23
-
-
Save takai/783774 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby; coding: utf-8-unix -*- | |
require 'benchmark' | |
Benchmark.bm(10) do |bm| | |
a = nil | |
bm.report 'ternary op' do | |
10000.times { a ? a.name : 'unknown' } | |
end | |
bm.report 'rescue' do | |
10000.times { a.name rescue 'unknown' } | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% ruby rescue.rb | |
user system total real | |
ternary op 0.000000 0.000000 0.000000 ( 0.002311) | |
rescue 0.100000 0.010000 0.110000 ( 0.118088) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment