esharris has asked for the wisdom of the Perl Monks concerning the following question:

How does the perl system implement arrays and hashes? I tried to look for this information using google, but was unsuccessful. I want to understand the efficiency of base operations, like shift, because I've been asked to make my perl scripts run faster.

Replies are listed 'Best First'.
Re: system implementation of arrays
by Corion (Patriarch) on Jan 23, 2006 at 13:57 UTC

    lhoward wrote Shift, Pop, Unshift and Push with Impunity!, which gives you a shallow overview. There also is Perlguts Illustrated, which tells you about the Perl data types and how they are implemented at the C level.

    Whenever it comes to optimizing Perl, the most time is gained by making the program do less work. This means, use an optimal algorithm instead of trying to micro-optimize how you use arrays or hashes.

    If you want to look in the direction of micro-optimizations, first do a benchmark with Devel::Dprof before trying to guess where your program spends most of its time.

      To backup what Corion said about optimizing and profiling, there's a good article on perl.com about profiling. Includes a decent real world example of taking a script's execution time from 10 seconds to 4 seconds.

      Cheers,

      Brent

      -- Yeah, I'm a Delt.
Re: system implementation of arrays
by GrandFather (Saint) on Jan 23, 2006 at 18:03 UTC