Skip to content

Instantly share code, notes, and snippets.

@dominikh
Created October 12, 2009 01:17
Show Gist options
  • Save dominikh/208029 to your computer and use it in GitHub Desktop.
Save dominikh/208029 to your computer and use it in GitHub Desktop.
require 'benchmark'
n = 1_000_000
Benchmark.bmbm do |x|
x.report("Double quotes") do
n.times do
str = "A simple string"
end
end
x.report("Single quotes") do
n.times do
str = 'A simple string'
end
end
x.report("evaled doube quotes") do
n.times do
eval(%q("hello world"))
end
end
x.report("evaled single quotes") do
n.times do
eval(%q('hello world'))
end
end
end
# Rehearsal --------------------------------------------------------
# Double quotes 0.510000 0.000000 0.510000 ( 0.513340)
# Single quotes 0.630000 0.000000 0.630000 ( 0.645145)
# evaled doube quotes 19.400000 0.050000 19.450000 ( 19.496075)
# evaled single quotes 19.480000 0.040000 19.520000 ( 19.534261)
# ---------------------------------------------- total: 40.110000sec
# user system total real
# Double quotes 0.510000 0.000000 0.510000 ( 0.511511)
# Single quotes 0.510000 0.000000 0.510000 ( 0.515970)
# evaled doube quotes 19.430000 0.040000 19.470000 ( 19.496095)
# evaled single quotes 19.570000 0.040000 19.610000 ( 19.670092)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment