in reply to Re: work with Array of Arrays
in thread work with Array of Arrays
my $count =0; foreach my $column (@{$AoA[$i]}){ $count ++; }
When all you do in the loop is increment, you might as well just write
my $count = @{$AoA[$i]};
which, btw, is approximately N times faster, with N being the size of the array:
use Benchmark 'cmpthese'; my @AoA; $AoA[42] = [ (1) x 1000 ]; cmpthese(-1, { counted => sub { my $count =0; foreach my $column (@{$AoA[42]}){ $count ++; } }, direct => sub { my $count = @{$AoA[42]}; }, } ); __END__ Rate counted direct counted 11821/s -- -100% direct 9267717/s 78297% --
|
|---|