mr.dunstan has asked for the wisdom of the Perl Monks concerning the following question:

Can mighty perl make an array of 40,000 hashes?

I could try to explain why but the details would be boring, too complicated, or just plain silly.

Humble novice,
mr.dunstan

Replies are listed 'Best First'.
Re: Array of Hashes - Too Big?
by TGI (Parson) on Jun 20, 2001 at 04:22 UTC

    Got RAM?

    C:\>perl -e "foreach (1..40_000){push @foo, {}}; print scalar @foo" 40000

    If you've got enough RAM, I don't see why not. You may want to look at some sort of tied, disk resident data structure, it will be slower but might not eat all your RAM. Since I still haven't mastered tie, someone smarter that I shall have to go into more detail, but I bet you could tie an array to a DBM file and just use your array index for the keys.


    TGI says moo

Re: Array of Hashes - Too Big?
by mr.nick (Chaplain) on Jun 20, 2001 at 04:27 UTC
    Did you try it? :)
    #!/usr/bin/perl -w use strict; use Data::Dumper; my @a; push @a,{ "$_" => 1 } for 1..40000; print Dumper @a[30000..30010];
    This takes < 1 second to complete on my ~666Mhz box.

    mr.nick ...

      1.22 seconds on a an UltraSparc 30, with 250MHz UltraSPARC-II and 256M of memory.

      I'm impressed with how fast perl did that, especially on my workstation, which normally runs everything extremely sloooow.

      -xPhase

Re: Array of Hashes - Mo' benchmarks
by gregor42 (Parson) on Jun 20, 2001 at 23:52 UTC

    As noted before, it's all about RAM.

    I have 256Mb of RAM in my system & it took about 25 seconds to run the above code, slightly modified, to process 400,000 hashes. This was with The Palm Desktop, Mozilla & Outlook running in the background under Windoze NT on a 500Mhz P3.

    Is that enough of a real world example for you? (;



    Wait! This isn't a Parachute, this is a Backpack!