Gaspard Bucher
9/16/2007 8:52:00 PM
I just did a stupid test :
[
["string last char", 'jdhduiehspdshfgie494hfps9e4',
'jdhduiehspdshfgie494hfps9e2'],
["symbol last char", :'jdhduiehspdshfgie494hfps9e4',
:'jdhduiehspdshfgie494hfps9e2'],
["string first char", 'jdhduiehspdshfgie494hfps9e4',
'jdhduiehspdshfgie494hfps9e2'],
["symbol first char", :'jdhduiehspdshfgie494hfps9e4',
:'kdhduiehspdshfgie494hfps9e4'],
["string same ", 'jdhduiehspdshfgie494hfps9e4',
'jdhduiehspdshfgie494hfps9e4'],
["symbol same ", :'jdhduiehspdshfgie494hfps9e4',
:'jdhduiehspdshfgie494hfps9e4'],
].each do |m,a,b|
t = Time.now
x = 0
y = 0
1_000_000.times do
if a == b
x += 1
else
y += 1
end
end
puts "#{m}: #{(Time.now - t).to_f} (#{x},#{y})"
end
Here are the results. You gain 10% speed by using symbols in such a situation.
string last char: 2.782326 (0,1000000)
symbol last char: 2.42484 (0,1000000)
string first char: 2.650707 (0,1000000)
symbol first char: 2.470714 (0,1000000)
string same : 2.737924 (1000000,0)
symbol same : 2.401426 (1000000,0)