Skip to content

Instantly share code, notes, and snippets.

@toothrot
Created April 22, 2011 00:09
Show Gist options
  • Save toothrot/935758 to your computer and use it in GitHub Desktop.
Save toothrot/935758 to your computer and use it in GitHub Desktop.
Single vs Double quotes
require 'benchmark'
Benchmark.bmbm do |b|
b.report("single") do
10_000.times do
'some string'
end
end
b.report("double") do
10_000.times do
"some string"
end
end
b.report("double 2") do
10_000.times do
"some string#{nil}"
end
end
b.report("single") do
10_000.times do
'some string'
end
end
end
__END__
Rehearsal --------------------------------------------
single 0.000000 0.000000 0.000000 ( 0.002007)
double 0.010000 0.000000 0.010000 ( 0.001456)
double 2 0.000000 0.000000 0.000000 ( 0.006717)
single 0.000000 0.000000 0.000000 ( 0.000993)
----------------------------------- total: 0.010000sec
user system total real
single 0.000000 0.000000 0.000000 ( 0.000994)
double 0.000000 0.000000 0.000000 ( 0.000814)
double 2 0.010000 0.000000 0.010000 ( 0.004737)
single 0.000000 0.000000 0.000000 ( 0.000843)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment