Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Formatting dynamic method names

by AnomalousMonk (Abbot)
on Oct 10, 2009 at 20:15 UTC ( #800477=note: print w/ replies, xml ) Need Help??


in reply to Formatting dynamic method names

sub temp_var { for ( keys %hash ) { my $method = "set_$_"; $object->$method( $hash{$_} ); } }
This benchmark code also includes the creation of a lexical scalar as well as assignment to it. The benchmark would be slightly more accurate (and slightly faster) if the lexical were defined outside the loop and used inside. (However, I doubt the speed difference would be significant.)

I would agree with zwon in preferring the 'temp var' approach.


Comment on Re: Formatting dynamic method names
Download Code
Re^2: Formatting dynamic method names
by clinton (Priest) on Oct 11, 2009 at 10:24 UTC

    Interesting - here are the results:

    Rate deref temp_var reused_lexic +al deref 173010/s -- -21% -2 +7% temp_var 218818/s 26% -- - +8% reused_lexical 238095/s 38% 9% +--

    (Note: these benchmarks are for interest only, and are firmly in the field of premature optimization)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2014-10-26 08:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (152 votes), past polls