my @arr = qw( one two three );
sub while_with_shift_push {
my $ref;
my @cp = @arr;
push( @$ref, $_ ) while( $_ = shift( @cp ) );
return $ref;
}
sub for_with_push {
my $ref;
my @cp = @arr;
push( @$ref, shift( @cp ) ) for ( 0..$#cp );
return $ref;
}
sub splice_it {
my $ref;
my @cp = @arr;
push( @$ref, splice( @cp ) );
return $ref;
}
sub push_with_clear {
my @cp = @arr;
my $ref;
push( @$ref, @cp );
@cp = ();
return $ref;
}
####
Rate for_with_push while_with_shift_push push_with_clear splice_it
for_with_push 160238/s -- -9% -32% -43%
while_with_shift_push 175370/s 9% -- -26% -37%
push_with_clear 237079/s 48% 35% -- -15%
splice_it 280139/s 75% 60% 18% --
####
Rate for_with_push splice_it push_with_clear while_with_shift_push
for_with_push 15.8/s -- -47% -50% -77%
splice_it 29.6/s 88% -- -5% -56%
push_with_clear 31.3/s 98% 6% -- -54%
while_with_shift_push 67.7/s 330% 129% 117% --
####
for_with_push 131415/s -- -14% -43% -45%
while_with_shift_push 152026/s 16% -- -34% -37%
push_with_clear 231941/s 76% 53% -- -4%
splice_it 240402/s 83% 58% 4% --
####
Rate for_with_push while_with_shift_push splice_it push_with_clear
for_with_push 73074/s -- -1% -45% -46%
while_with_shift_push 73539/s 1% -- -45% -46%
splice_it 133132/s 82% 81% -- -2%
push_with_clear 136236/s 86% 85% 2% --