Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Show that using references is faster

by Ven'Tatsu (Deacon)
on Oct 04, 2004 at 22:12 UTC ( [id://396413]=note: print w/replies, xml ) Need Help??


in reply to Show that using references is faster

My guess is that sort is taking the majority of the time in your code. If your argument list is long enough passing it in as a list can take a decent chunk of time.
use Benchmark qw(cmpthese); @a = 1..1_000_000; sub flat { my $array = \@_ } sub flatcopy { my @copy = @_ } sub byref { my $array = $_[0] } sub refcopy { my @copy = @$_[0] } cmpthese(-1, { flat => sub { flat(@a) }, flatcopy => sub { flatcopy(@a) }, byref => sub { byref(@a) }, refcopy => sub { refcopy(@a) } }); __END__ Rate flatcopy flat refcopy byref flatcopy 3.24/s -- -77% -91% -91% flat 14.3/s 342% -- -59% -61% refcopy 35.3/s 987% 146% -- -3% byref 36.3/s 1020% 153% 3% --

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-03-29 15:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found