Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Optimizing the bejeezus out of a sub

by tilly (Archbishop)
on Jun 24, 2003 at 17:54 UTC ( [id://268616]=note: print w/replies, xml ) Need Help??


in reply to Optimizing the bejeezus out of a sub

A number of comments, most of which shouldn't affect performance, but a couple of which might.
  1. Why are you predeclaring $val, $sec, and $v? Move the declaration inline. I doubt that there is any performance difference but it keeps someone (like me) from wondering whether, for instance, $v is global.
  2. Try assigning @_ to $ret, then decrement $ret on skipped sections. Theoretically faster, though probably imperceptibly so.
  3. You could select $fh temporarily rather than printing to it each time.
  4. Why are you writing your own templating engine? I would be inclined to use one of the many ones out there already, several of which have been optimized far more than I would feel like doing it.
  • Comment on Re: Optimizing the bejeezus out of a sub

Replies are listed 'Best First'.
Re: Re: Optimizing the bejeezus out of a sub
by sgifford (Prior) on Jun 24, 2003 at 18:31 UTC

    1: I did this to see if it helped performance. It didn't, but I didn't change it back before posting.

    2-3: I'll try these and see if they do anything interesting.

    4: Yeah, I know. I've got a seriously hacked up copy of CGI::FastTemplate that I've been using for years, so it has a style that I've gotten used to and, more importantly, that the Web page designers I work with have gotten used to. It's also a PITA to maintain, so I rewrote it to be more legible (and I hoped faster, but it turns out not). I'm trying to decide if I should keep my hacked up copy of CGI::FastTemplate, use my rewritten replacement, or just use another engine. That got me started benchmarking different templating engines, which led to optimizing this sub. Maybe when I've done a little more research I'll Seek some Wisdom on the merits of the different templating engines...

Re: Re: Optimizing the bejeezus out of a sub
by sgifford (Prior) on Jun 24, 2003 at 18:42 UTC

    2: Didn't really help (a little slower, but probably just measuring error)

    Before:

    %Time ExclSec CumulS #Calls sec/call Csec/c  Name
     48.8   20.83 20.710 130000   0.0002 0.0002  FTS::printto
    

    After 2

    %Time ExclSec CumulS #Calls sec/call Csec/c  Name
     51.2   23.74 23.620 130000   0.0002 0.0002  FTS::printto
    

    3: Ditto.

    After 3

    %Time ExclSec CumulS #Calls sec/call Csec/c  Name
     49.5   21.00 20.880 130000   0.0002 0.0002  FTS::printto
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://268616]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-25 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found