I'm not sure that this is exactly a great benchmark, but it seems fairly clear that appending to a string is a generally a bit quicker than pushing to an array.
#! perl -slw
use strict;
use Benchmark qw[cmpthese];
cmpthese( -3, {
append1k => q[
my $buffer .= 'x' x 1024 for 0..5;
],
push1k => q[
my @buffer;
push @buffer, 'X' x 1024 for 0..5;
],
});
cmpthese( -3, {
append8k => q[
my $buffer .= 'x' x 8192 for 0..5;
],
push8k => q[
my @buffer;
push @buffer, 'X' x 8192 for 0..5;
],
});
cmpthese( -3, {
append64k => q[
my $buffer .= 'x' x 65536 for 0..5;
],
push64k => q[
my @buffer;
push @buffer, 'X' x 65536 for 0..5;
],
});