Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^4: Does @{ } copy arrays?

by ikegami (Patriarch)
on Oct 23, 2009 at 20:57 UTC ( [id://802978]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Does @{ } copy arrays?
in thread Does @{ } copy arrays?

The point is that $#a should be faster than @a-1. That's not what you are testing. You have have an extra operation in your $#a test instead of having one less.

#!/usr/bin/perl use strict; use warnings; use Benchmark qw(cmpthese); our @a = qw( Once upon a time in a galaxy far far away ); cmpthese(-3, { cnt_minus_1 => 'my $x = @a-1;', last_idx => 'my $x = $#a;', });
Rate last_idx cnt_minus_1 last_idx 3225597/s -- -25% cnt_minus_1 4308243/s 34% --

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://802978]
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-04-25 13:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found