Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Formatting dynamic method names

by AnomalousMonk (Chancellor)
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.

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2018-06-21 18:40 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (118 votes). Check out past polls.