Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Formatting dynamic method names

by AnomalousMonk (Archbishop)
on Oct 10, 2009 at 20:15 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-03-19 02:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found