Created
May 8, 2022 05:54
-
-
Save azumakuniyuki/db0c1e20e1459327dd83bafc69fda8fa to your computer and use it in GitHub Desktop.
${^MATCH} variable with /p modifier
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
#!/usr/bin/env perl | |
# Captured $1 vs. ${^MATCH} | |
use strict; | |
use warnings; | |
use Benchmark ':all'; | |
use Test::More 'no_plan'; | |
my $q = 'neko-nyaan-cat'; | |
sub cv { | |
my $v = shift; $v =~ /(n[a-z]{4})/; | |
return $1; | |
} | |
sub mv { | |
my $v = shift; $v =~ /n[a-z]{4}/p; | |
return ${^MATCH}; | |
} | |
is cv($q), 'nyaan'; | |
is mv($q), 'nyaan'; | |
printf("Running with Perl %s on %s\n%s\n", $^V, $^O, '-' x 80); | |
cmpthese(6e6, { | |
'$1' => sub { cv($q) }, | |
'${^MATCH}' => sub { mv($q) }, | |
} | |
); | |
__END__ | |
Running with Perl v5.30.0 on darwin | |
-------------------------------------------------------------------------------- | |
Rate $1 ${^MATCH} | |
$1 1916933/s -- -9% | |
${^MATCH} 2097902/s 9% -- | |
Running with Perl v5.32.0 on darwin | |
-------------------------------------------------------------------------------- | |
Rate $1 ${^MATCH} | |
$1 1929260/s -- -6% | |
${^MATCH} 2054795/s 7% -- | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment