Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Formatting dynamic method names

by clinton (Priest)
on Oct 11, 2009 at 10:24 UTC ( [id://800530]=note: print w/replies, xml ) Need Help??


in reply to Re: Formatting dynamic method names
in thread Formatting dynamic method names

Interesting - here are the results:

#!/usr/bin/perl use strict; use warnings; use Benchmark qw(cmpthese); package foo; { sub set_var1 { } sub set_var2 { } sub set_var3 { } sub set_var4 { } sub set_var5 { } } package main; my $object = bless {}, 'foo'; my %hash = map { ( "var$_" => $_ ) } ( 1 .. 5 ); sub temp_var { for ( keys %hash ) { my $method = "set_$_"; $object->$method( $hash{$_} ); } } sub reused_lexical { my $method; for ( keys %hash ) { $method = "set_$_"; $object->$method( $hash{$_} ); } } sub deref { for ( keys %hash ) { $object ->${ \"set_$_" }( $hash{$_} ); } } cmpthese( 1_000_000, { temp_var => \&temp_var, deref => \&deref, reused_lexical => \&reused_lexical, } );
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://800530]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-03-19 03:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found