Hi, I have some wierd results measuring Ruby's hash operations,
particulary indexing hash using two member string array. Have a look:

>> require 'benchmark'
=> false
>> puts(Benchmark.measure do
?>   h = {}
>>   1000000.times do |i|
?>     i1 = rand(100)
>>     i2 = rand(100)
>>     a = [i1.to_s, i2.to_s]
>>     h[a] ||= 0
>>     h[a] += 1
>>   end
>>   puts h.size
>> end)
10000
 12.900000   0.050000  12.950000 ( 13.088721)
=> nil
>> puts(Benchmark.measure do
?>   h = {}
>>   1000000.times do |i|
?>     i1 = rand(100)
>>     i2 = rand(100)
>>     a = [i1.to_s + '00000', i2.to_s + '00000']
>>     h[a] ||= 0
>>     h[a] += 1
>>   end
>>   puts h.size
>> end)
10000
  7.700000   0.040000   7.740000 (  7.858381)
=> nil

In other words, I just made array members slightly longer and working
with hash was considerably faster.

Why's that happening?

BTW,

jablan-mbp:~ $ ruby -v
ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]