This C style approach is 50% faster than the push approach posted earlier. Ugly but fast.
use Benchmark; @in = (1,2,3,4,5,6,7,8,9,0); timethese ( 100000, { 'C-style' => 'for my $i ( 0 .. $#in ) { $i % 2 ? $out2[int($i/2)] = $in[$i] : $out1[$i/2] = $i +n[$i] }', 'push' => 'for my $i ( 0 .. $#in ) { $i % 2 ? push @out2, $in[$i] : push @out1, $in[$i]; }' } ); __DATA__ Benchmark: timing 100000 iterations of C-style, push... C-style: 13 wallclock secs (12.97 usr + 0.00 sys = 12.97 CPU) @ 77 +10.10/s (n=100000) push: 18 wallclock secs (18.79 usr + 0.00 sys = 18.79 CPU) @ 53 +21.98/s (n=100000)
In reply to Re: How can I skip an element in an array whilst reading...
by tachyon
in thread How can I skip an element in an array whilst reading...
by Blanco
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |