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% --
|
|---|