use warnings; use strict; use Benchmark qw/cmpthese/; use List::Util qw/shuffle/; my @numbers = ( 0..20 ); my @indices = shuffle 0..$#numbers; my @expect = ( 0..2,4..20 ); use constant TEST => 0; cmpthese(-2, { splice => sub { my @output = @numbers; for my $index (@indices){ splice @output, 0, 1; } join("\0", @output) eq join("\0", @expect) or die if TEST; }, grep => sub { # https://www.perlmonks.org/?node_id=11123877 my @output; for my $index (@indices){ @output = @numbers[ grep $_ != $index, 0 .. $#numbers ]; } join("\0", @output) eq join("\0", @expect) or die if TEST; }, hash => sub { my %ha; @ha{0..$#numbers} = @numbers; for my $index (@indices){ delete $ha{$index}; } my @output = map { $ha{$_} } sort keys %ha; join("\0", @output) eq join("\0", @expect) or die if TEST; }, }); __END__ Rate grep hash splice grep 30916/s -- -85% -96% hash 205775/s 566% -- -71% splice 707918/s 2190% 244% --