in reply to Making my Perl program a bit faster

What parts of Perl are known to be a bit slower or less efficient than others? And what parts of Perl are super fast and should be used more?
What a silly question to ask. One doesn't use parts of Perl because they are fast, one uses parts of Perl that solve their problem. It's like taking the train: the most important factor in deciding which train to take isn't the speed of the train, but whether it brings me to where I want to be.

BTW, Perl doesn't have things that are "not fast" for the sake of being "not fast". They may be "not fast" because they do a lot of stuff. It would be silly to avoid them if the stuff they do is what you want to be done.

  • Comment on Re: Making my Perl program a bit faster

Replies are listed 'Best First'.
Re^2: Making my Perl program a bit faster
by ww (Archbishop) on Jul 08, 2009 at 13:03 UTC

    ....um...er.... not quite or, at least, not always:

    s/(the most important factor in deciding which train to take isn't the speed of the train, but whether it brings me to where I want to be)/\1 when I want to get there./

    Sometimes, the [bicycle|car|plane] is the right choice (cf Moritz advice re letting the database do some of the work).

    Update:   AnomalousMonk (thanks!) notes: s/(...)/$1 when I want to get there./ vice s/(...)/\1 when I want to get there./ : capture variable is preferable to backreference in string interpolation (backreference generates warning).

Re^2: Making my Perl program a bit faster
by mrguy123 (Hermit) on Jul 08, 2009 at 13:19 UTC
    Hi JavaFan,
    First of all, if one's workplace uses Perl, then one would use Perl all the time, and indeed try to program it as efficiently as possible.
    Also, I am not a huge expert in this (the reason why I am asking this question), but like any programming language, there are things Perl is very good at (e.g. regexes and parsing files) and not so good at (hardcore mathematical computing if I'm not mistaken).
    The purpose of my question was to get a bit more info about this issue, and to gather a few tips (e.g. use a profiler).

    I think the issue of Perl and efficiency is an interesting one (in fact it might be a good idea for my next Perl Mongers lecture after I understand it a bit more), and not so silly as you might think.

    Cheers mrguy123
      Yes, but even if being "very good" at regexes means regular expression matching in Perl was fast, it still doesn't make sense to avoid "hardcore mathematical computing" Perl isn't good at in lieu of regexes if you have to do arithmetic. It's hard to do any non-trivial arithmetic with regular expressions, and unlikely to be more efficient than regular "hardcore mathematical computing".

      Even if your hammers are above average, and your screwdrivers aren't, it still doesn't make sense to hammer in screws.

        Not avoid, but be aware, I think.
        TIMTOWTDI is not always Perl's best feature, but if one way is a bit faster than the other, it might be a good idea to use it.