Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Question about curious performance of if...elsif block

by sundialsvc4 (Abbot)
on Jan 16, 2012 at 23:52 UTC ( [id://948228]=note: print w/replies, xml ) Need Help??


in reply to Question about curious performance of if...elsif block

One trick that might help here is to define an array (or a hash...) of subs; that is to say, of “code references.”   Directly fetch and execute (if it exists) the specific subroutine that you want to execute.   So you’re not performing 39 if-tests in a row in order to determine that you want to execute subroutine #40...

I am not asserting that it will help in your particular, very rarified and performance-hungry case.   Only empirical testing would establish that.

Replies are listed 'Best First'.
Re^2: Question about curious performance of if...elsif block
by markseger (Beadle) on Jan 17, 2012 at 12:28 UTC
    > Directly fetch and execute (if it exists) the specific subroutine that you want to execute.

    For those of use who not only remember but actually used them, this sounds like fortran's computed goto statement. However in my case it's not that I want to execute different subs, but rather blocks of code. Can I do the same thing using labels? That really would make it a computed goto. ;)

    However I would still like to hear any and all theories about why this curious behavior. The script in question is 'collectl', an opensouce project I released a number of years ago. It's a very light-weight system monitoring tool and am always looking for way to make it even lighter-weight and this feels like an opportunity.

    On a different note, my comments about rhel6.2 were wrong. I forgot the VM has <100 processes so I'm actually executing have the number of tests and so the performance improvement over the earlier tests seems as little better but not that much better.

    -mark

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-19 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found