Just as a data point, I ran this on my workstation. Perl v5.8.7 built for i486-linux-gnu-thread-multi on Debian.

I ran it a bunch of times, with the "undef %testHash1;" in and out. The rate varied from 111,000/sec to 250,000/sec, but never anywhere remotely close to your 9000. So, you may have issues with your particular release or platform, but this does not seem to be common to all installations.

Update:

Doing some quick reading, I checked out recipie 5.13 in Perl Cookbook. It has a sentence that might shed some light: "Perl already shares keys between hashes, so if you already have a hash with "Apple" as a key, Perl won't need to allocate memory for another copy of "Apple" when you had an entry whose key is "Apple" to another hash".

Since both keys are about "PROTEST SONG", I'd be most interested if you'd re-run your benchmarks with an entirely different pattern on your second hash key...

Another Update:

After seeing Ikegami's results on Windows, I decided to try it on an old NT4 box. Perl version is ActiveState build 813 of Perl 5.8.7. With the undef in place, keys per second were 47619 and 66667. Weird.


In reply to Re: Use of undef slowing down perl? by pboin
in thread Use of undef slowing down perl? by thalej

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.