Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2015-03-01 15:24 GMT
Find Nodes?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:

    Results (7 votes), past polls