in reply to How best to tell when my hash is "full" (all values defined)?

OK, since I am feeling kind of curious today, I decided to try benchmarking the various approaches. On my first run (with 100 iterations), I got:
Method 1 is foreach my $line (`top -b -n 1`) and creating the hash keys as we go.
Method 2 is foreach my $line (`top -b -n 1`) and precreating the hash keys.
Method 3 is foreach my $line (@raw) where @raw=`top -b -n 1`and precreating the hash keys.
Method 4 is while (my $line = <TOP>) with open(TOP, "top -b -n 1|") and precreating the hash keys.
Method 1 mean:  0.560507924556732 stddev:  0.00320759260168446!
Method 2 mean:  0.560737266540527 stddev:  0.00290542841782241!
Method 3 mean:  0.561151208877563 stddev:  0.00359781593804784!
Method 4 mean:  0.558518676757812 stddev:  0.00518282488688389!
T-stat for mean 1 and mean 2 is 0.529922998231174
T-stat for mean 1 and mean 3 is 1.33459955560607
T-stat for mean 1 and mean 4 is 3.26368009466516
T-stat for mean 2 and mean 3 is 0.895111546983644
T-stat for mean 2 and mean 4 is 3.73396330152602
T-stat for mean 3 and mean 4 is 4.17253188415264

Note that I did not throw away outliers, and I have no control over what other users were doing on the machine, so this is by no means rigorous, yet I think it's still useful. I think it's pretty clear that piped opens beat the other methods hands down--good call, McDarren!

Anyway, this led me to try another combination with the same methodology and under the same conditions, the results of which follow:
Method 1 is while (my $line = <TOP>) with open(TOP, "top -b -n 1|") and creating the hash keys as we go.
Method 2 is while (my $line = <TOP>) with open(TOP, "top -b -n 1|") and precreating the hash keys.
Method 1 mean:  0.557748141288757 stddev:  0.00368823257386979!
Method 2 mean:  0.558288831710816 stddev:  0.00673477747628604!
T-stat for mean 1 and mean 2 is 0.704155995405561
A t-stat of 0.7 for r=100 gives you a confidence of between 75 and 90%; that's not bad. It might be just as much an artifact of the escape clause as anything else, but it's interesting.

Code available upon request.

Thanks again,
T.

I like computer programming because it's like Legos for the mind.
  • Comment on Re: How best to tell when my hash is "full" (all values defined)?

Replies are listed 'Best First'.
Re^2: How best to tell when my hash is "full" (all values defined)?
by OfficeLinebacker (Chaplain) on Dec 18, 2006 at 18:10 UTC
    OK, one last test and I promise I'm done. I tried the same as above but with 1000 iterations:
    Method 5 is while (my $line = <TOP>) with open(TOP, "top -b -n 1|") and creating the hash keys as we go.
    Method 6 is while (my $line = <TOP>) with open(TOP, "top -b -n 1|") and precreating the hash keys.
    Method 5 mean:  0.557365287780762 stddev:  0.00308031218339066!
    Method 6 mean:  0.557536187648773 stddev:  0.00521559192260659!
    T-stat for mean 5 and mean 6 is 0.892202830875346
    
    So the mean is slightly significantly lower for creating on-the-fly, and the variance is significantly lower for that approach. Interesting.

    I like computer programming because it's like Legos for the mind.