#!/usr/bin/perl use strict; use warnings; use Benchmark qw(cmpthese); my $N = 2_000_000; my @topush = ( "Hello array!", 123 ); my @pusharray; my @splicearray; my @splicearray2; my @forarray; $#splicearray = ($N * scalar @topush) - 1; sub pushit { push @pusharray, @topush; } my $sppos = 0; sub spliceit { splice @splicearray, $sppos, scalar @topush, @topush; $sppos += @topush; } sub spliceit2 { splice @splicearray2, @splicearray2, scalar @topush, @topush; } sub forit { for my $value (@topush) { $forarray[ ++$#forarray ] = $value; } } cmpthese( $N, { 'push' => \&pushit, 'splice' => \&spliceit, 'splice2' => \&spliceit2, 'for' => \&forit, } );