On Tue, Jul 28, 2009 at 6:50 PM, jablan<jablan / gmail.com> wrote:
<snip>
Benchmarking is tricky business. I am not sure my benchmarks are worth
much, but they do not confirm your results. BTW using: ruby 1.9.1p243
(2009-07-16 revision 24175) [i686-linux]

First you really should not bm inside irb. Second you should use bmbm
for rehearsals, but even with that you could get bitten by tons of
things happening on your machine.
Nevertheless for whats worth it - and because I adore benchmarking ;)
- here is my code and results:

require 'benchmark'

N = 100_000
5.times do
  Benchmark.bmbm do | bm |
    h = Hash::new( 0 )
  bm.report( "2 chars" ) do
    N.times do
      h[ [rand(100).to_s, rand(100).to_s] ] += 1
    end
  end
  h = Hash::new( 0 )
  bm.report( "7 chars" ) do
    N.times do
      h[ [rand(100).to_s + "00000", rand(100).to_s + "00000" ] ] += 1
    end
  end
  end
end
robert@siena:~/log/ruby/ML 19:50:13
519/25 > ruby bm1.rb
Rehearsal -------------------------------------------
2 chars   0.700000   0.010000   0.710000 (  0.953483)
7 chars   0.960000   0.010000   0.970000 (  1.367117)
---------------------------------- total: 1.680000sec

              user     system      total        real
2 chars   0.740000   0.020000   0.760000 (  1.031102)
7 chars   1.010000   0.020000   1.030000 (  1.323072)
Rehearsal -------------------------------------------
2 chars   0.720000   0.000000   0.720000 (  0.955180)
7 chars   0.980000   0.010000   0.990000 (  1.320693)
---------------------------------- total: 1.710000sec

              user     system      total        real
2 chars   0.710000   0.000000   0.710000 (  0.923019)
7 chars   0.900000   0.010000   0.910000 (  1.262338)
Rehearsal -------------------------------------------
2 chars   0.700000   0.000000   0.700000 (  0.926117)
7 chars   0.990000   0.020000   1.010000 (  1.356475)
---------------------------------- total: 1.710000sec

              user     system      total        real
2 chars   0.710000   0.000000   0.710000 (  0.940901)
7 chars   0.880000   0.020000   0.900000 (  1.269465)
Rehearsal -------------------------------------------
2 chars   0.700000   0.010000   0.710000 (  1.016537)
7 chars   0.990000   0.010000   1.000000 (  1.360516)
---------------------------------- total: 1.710000sec

              user     system      total        real
2 chars   0.720000   0.010000   0.730000 (  0.920533)
7 chars   0.920000   0.000000   0.920000 (  1.198681)
Rehearsal -------------------------------------------
2 chars   0.720000   0.010000   0.730000 (  0.946056)
7 chars   1.020000   0.010000   1.030000 (  1.343575)
---------------------------------- total: 1.760000sec

              user     system      total        real
2 chars   0.720000   0.010000   0.730000 (  1.023185)
7 chars   0.930000   0.000000   0.930000 (  1.211184)




-- 
Toutes les grandes personnes ont dÃÂbord ñÕdes enfants, mais peu
dÃÆntre elles sÃÆn souviennent.

All adults have been children first, but not many remember.

[Antoine de Saint-ExupñÓy]