
Untitled
By: a guest on
Jul 31st, 2012 | syntax:
None | size: 1.24 KB | hits: 10 | expires: Never
## quotes_test.rb
require 'benchmark'
Benchmark.bm do |x|
x.report ("single quotes") do
for i in 1..10000000
s = '1234567890qwertyuiopasdfghjklzxcvbnm'
end
end
x.report ("double quotes") do
for i in 1..10000000
s = "1234567890qwertyuiopasdfghjklzxcvbnm"
end
end
x.report ("single quotes with concatenation") do
for i in 1..10000000
s = '1234567890qwertyuiopasdfghjklzxcvbnm' + i.to_s
end
end
x.report ("double quotes with concatenation") do
for i in 1..10000000
s = "1234567890qwertyuiopasdfghjklzxcvbnm" + i.to_s
end
end
x.report ("double quotes with embedding") do
for i in 1..10000000
s = "1234567890qwertyuiopasdfghjklzxcvbnm#{i}"
end
end
end
# ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.5.0]
# user system total real
# single quotes 2.740000 0.010000 2.750000 ( 2.745104)
# double quotes 2.740000 0.000000 2.740000 ( 2.748085)
# single quotes with concatenation 11.420000 0.020000 11.440000 ( 11.428245)
# double quotes with concatenation 11.400000 0.010000 11.410000 ( 11.403773)
# double quotes with embedding 11.210000 0.030000 11.240000 ( 11.223446)