Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Formatting dynamic method names

by AnomalousMonk (Canon)
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
Replies are listed 'Best First'.
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 drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2015-11-27 07:52 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (720 votes), past polls