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

Re: Ampersands and sub speed

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.