-
-
Save mpapec/837f9457b61738430fc74c34b93d6732 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
perl -Mstrict -wE' | |
use Benchmark qw(:all); | |
my $arr1 = [ 1 .. 10_000 ]; | |
my $arr2 = [ 1 .. 10_000 ]; | |
my $arr3 = [ 1 .. 10_000 ]; | |
cmpthese(-3, { | |
inPlace => sub { | |
@$arr1 = grep { $_ ne "100" } @$arr1; | |
}, | |
newArray => sub { | |
$arr2 = [ grep { $_ ne "100" } @$arr2 ]; | |
}, | |
newArray2 => sub { | |
$arr3 = sub {\@_}->(grep { $_ ne "100" } @$arr3); | |
} | |
}); | |
' | |
# | |
# | |
Rate inPlace newArray newArray2 | |
inPlace 377/s -- -22% -72% | |
newArray 486/s 29% -- -64% | |
newArray2 1334/s 254% 174% -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment