-
-
Save dctabuyz/c70b741d83ca8beb116ce7bc67392853 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use utf8; | |
use v5.26.0; | |
use List::Util qw/first any/; | |
use Benchmark qw(:all); | |
for my $m ( 1 .. 3 ) { | |
my $max = $m * 1000; | |
my @data = map { "x$_" } ( 1 .. $max ); | |
timethese(100_000, { | |
"foreach x $m" => sub { foreach ( @data ) { return 1 if $_ eq $max; } return 0; }, | |
"any x $m" => sub { return 1 if any {$_ eq $max} ( @data ); return 0; }, | |
"grep x $m" => sub { return 1 if scalar grep {$_ eq $max} ( @data ); return 0; }, | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment