Skip to content

Instantly share code, notes, and snippets.

@tyre
Created February 16, 2014 21:06
Show Gist options
  • Save tyre/9040631 to your computer and use it in GitHub Desktop.
Save tyre/9040631 to your computer and use it in GitHub Desktop.
Ruby quotes
Benchmark.bmbm do |b|
b.report('single quotes') { 37_000_000.times { 'Six sets straight, ace, cut em in the bathroom.' } }
b.report('double quotes') { 37_000_000.times { "Six sets straight, ace, cut em in the bathroom." } }
b.report('%q') { 37_000_000.times { %q{Six sets straight, ace, cut em in the bathroom.} } }
b.report('%Q') { 37_000_000.times { %Q{Six sets straight, ace, cut em in the bathroom.} } }
end
# user system total real
# single quotes 3.480000 0.000000 3.480000 ( 3.481189)
# double quotes 3.510000 0.010000 3.520000 ( 3.507431)
# %q 3.490000 0.000000 3.490000 ( 3.487838)
# %Q 3.470000 0.000000 3.470000 ( 3.476493)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment