The first thing you want to do is profile your script. Use Devel::DProf and/or Devel::SmallProf to find out which parts of the script are taking the most time: optimize those first. (It turns out that most programmers have horrible intuition about which parts of the code are taking the most time, so profile instead of guessing.)

Once you have a list of hot-spots, optimize them. The best way to speed up code is to use a faster algorithm, especially for large data sets. Have a look around google for better algorithms. (On small data sets, it's sometimes best to use a simpler, "slower" algorithm: the faster ones tend to have high setup costs, and are only faster in the long run.) Failing that, there are lower-level optimizations that can be done: iterating over a list with foreach rather than indexing into it inside a C-style for loop, for example. (Programming Perl has a section on code optimization.)

If you've tried all that, and your code's still too slow, you might be able to post some of it here, tell us what you've tried, and get further advice.

Two non-Perl solutions: if time is more important than money, you should consider buying faster hardware. (If your process is using lots of memory and swapping, even $50 worth of RAM could make a huge difference if it cuts way down on disk accesses.) It might also be worth it to re-write your program in a faster language (C is the canonical example, but I've had good luck with compiled Haskell lately), especially if it's doing a lot of number crunching.

--
The hell with paco, vote for Erudil!
:wq


In reply to Re: Performance by FoxtrotUniform
in thread Performance by Jaspersan

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.