Replacing tasklist.exe with ps, your code worked with my machine and it shows while/each is faster and smaller.
1. About Speed
I noticed from your code, I was very unfair to while/each because I lack value assignment with foreach/keys test function. When I change Benchmark test function from
foreach my $k (keys %h){ }
to
foreach my $k (keys %h){ my $v=$h{$k}; }
, benchmark shows while/each becomes faster
case 10000 hash ready ... count=10000 Sat Nov 12 01:13:29 2011 ---------------------------------------- Rate test_each test_keys test_each 108/s -- -28% test_keys 151/s 40% -- ---------------------------------------- Sat Nov 12 01:14:22 2011 case 100000 hash ready ... count=100000 Sat Nov 12 01:14:23 2011 ---------------------------------------- Rate test_keys test_each test_keys 4.63/s -- -23% test_each 6.02/s 30% -- ---------------------------------------- Sat Nov 12 01:15:20 2011 case 1000000 hash ready ... count=1000000 Sat Nov 12 01:15:32 2011 ---------------------------------------- s/iter test_keys test_each test_keys 2.71 -- -30% test_each 1.89 43% -- ---------------------------------------- Sat Nov 12 01:16:35 2011 case 2000000 hash ready ... count=2000000 Sat Nov 12 01:19:32 2011 ---------------------------------------- s/iter test_keys test_each test_keys 5.69 -- -31% test_each 3.91 46% -- ---------------------------------------- Sat Nov 12 01:21:49 2011

2. About memory
With ps command, while/each loop shows very very small memory usage. Memory allocation of "keys" is significant.
$./025-6.pl -M1=keys -M2=pairs -N=1e6 hash built, starting timer Took 3.931463 and 39.000MB extra memory for 1000000 using keys/pairs m +ethod $./025-6.pl -M1=each -M2=pairs -N=1e6 hash built, starting timer Took 2.434757 and 1.000MB extra memory for 1000000 using each/pairs me +thod
It seems I miss something with GTop.

In reply to Re^10: Finding the size of a nested hash in a HoH by remiah
in thread Finding the size of a nested hash in a HoH by Jeri

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.