Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Ampersands and sub speed

by xdg (Monsignor)
on Oct 14, 2005 at 21:58 UTC ( [id://500385]=note: print w/replies, xml ) Need Help??


in reply to Ampersands and sub speed

Of course, where this really matters is doing something not doing nothing and there, of course, the delta is less significant. (Though still greater than zero.)

package Foo; sub do_something { my $i; $i++ for (1 .. 10) } package main; use strict; use warnings; use Benchmark qw( cmpthese ); my $foo = bless {}, 'Foo'; sub do_something { my $i; $i++ for (1 .. 10) } cmpthese( -1, { k1 => sub { $foo->do_something }, k2 => sub { Foo->do_something }, k3 => sub { Foo::do_something }, k4 => sub { do_something }, k5 => sub { &do_something }, });
Rate k2 k1 k4 k3 k5 k2 359975/s -- -3% -6% -7% -8% k1 369628/s 3% -- -3% -5% -6% k4 382293/s 6% 3% -- -2% -3% k3 388120/s 8% 5% 2% -- -1% k5 392991/s 9% 6% 3% 1% --

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-25 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found