#! /usr/bin/perl -w use strict; use Benchmark qw/cmpthese/; my @x = qw/a b c/; sub with_splice { my $aref = shift; splice( @$aref, 0, -1 ); } sub with_range { my $aref = shift; @{$aref}[0 .. ($#{$aref} - 1)] } print 'range ', join( ' ' => with_range(\@x) ), "\n"; print 'splice ', join( ' ' => with_splice(\@x) ), "\n"; my @z = 0 .. 100_000; cmpthese( shift || 2_000_000, { short_splice => sub { with_splice(\@x) }, short_range => sub { with_range (\@x) }, } ); cmpthese( shift || 1_000, { long_splice => sub { with_splice(\@z) }, long_range => sub { with_range (\@z) }, } ); __RESULTS__ range a b splice a b Benchmark: timing 2000000 iterations of short_range, short_splice... short_range: 9 wallclock secs ( 7.83 usr + 0.00 sys = 7.83 CPU) @ 255489.02/s (n=2000000) short_splice: 5 wallclock secs ( 5.06 usr + 0.01 sys = 5.07 CPU) @ 394453.00/s (n=2000000) Rate short_range short_splice short_range 255489/s -- -35% short_splice 394453/s 54% -- Benchmark: timing 1000 iterations of long_range, long_splice... long_range: 40 wallclock secs (39.73 usr + 0.02 sys = 39.74 CPU) @ 25.16/s (n=1000) long_splice: 0 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU) @ 128000.00/s (n=1000) (warning: too few iterations for a reliable count) Rate long_range long_splice long_range 25.2/s -- -100% long_splice 128000/s 508600% --