I suspect is it the memory related to object creation for Array.new(2){ =
Array.new(1){ Array.new( 20, rand(1) ) } }

With this line as originally
       h1[ "#{a}.#{b}.#{c}.#{d}" ] =3D Array.new(2){ Array.new(1){ =
Array.new( 20, rand(1) ) } }
I get 20.8 seconds

set to=20
      h1[ "#{a}.#{b}.#{c}.#{d}" ] =3D 3
I get 2.54 seconds

set to=20
       Array.new(2){ Array.new(1){ Array.new( 20, rand(1) ) } }

I get 3.75 seconds

set to=20
       # h1[ "#{a}.#{b}.#{c}.#{d}" ] =3D Array.new(2){ Array.new(1){ =
Array.new( 20, rand(1) ) } }

I get 0.47 seconds

Dave.

On 17 Mar 2011, at 12:56, Philip Rhoades wrote:

> People,
>=20
> In response to people's suggestions about speeding up my script by =
replacing output to many small files with output to one large file I =
have implemented a hash table I can write out with YAML.  However, I =
find as the hash table gets larger, the script slows down . . but when I =
try and work out what is happening by producing a small test script that =
does more or less the same thing, I can't reproduce the problem . .
>=20
> The test script is:
>=20
>=20
> #!/usr/bin/ruby
>=20
> h1 =3D Hash.new( 0 )
> srand =3D 0
>=20
> # seeds =3D [ '01', '01', '01', '22' ]
> # seeds =3D [ '01', '01', '20', '22' ]
> # seeds =3D [ '01', '32', '20', '22' ]
> seeds =3D [ '50', '32', '20', '22' ]
>=20
> for a in '01' .. seeds[0]
>  start =3D Time.now
> # puts a
>  for b in '01' .. seeds[1]
> #   puts b
>    for c in '01' .. seeds[2]
> #     puts c
>      for d in '01' .. seeds[3]
> #        print "#{d} "
>        h1[ "#{a}.#{b}.#{c}.#{d}" ] =3D Array.new(2){ Array.new(1){ =
Array.new( 20, rand(1) ) } }
>      end
> #     puts
>    end
> #   puts
>  end
> # puts
>  stop =3D Time.now
>  puts stop - start
> end
>=20
>=20
> The script is faster with the hash insertion commented out of course =
and the time between iterations of the outer loop are constant in both =
scripts - but they are longer and STILL constant with the insertion not =
commented out in the test script.  In my actual script, when the =
insertion is not commented out the time between iterations in the outer =
loop gets longer and longer eg 36 sec -> a few minutes before I kill it =
about half way through . .
>=20
> Can anyone suggest a way of working out why the production hash =
insertion behaves differently and somewhat unexpectedly?
>=20
> Thanks,
>=20
> Phil.
> --=20
> Philip Rhoades
>=20
> GPO Box 3411
> Sydney NSW	2001
> Australia
> E-mail:  phil / pricom.com.au
>=20