Created
March 1, 2015 00:28
-
-
Save bayashi/ffc7edd26f609af54c46 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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use utf8; | |
use Benchmark qw(cmpthese); | |
my $h = '25'; | |
my $pattern = '((?:(?:'.$h.'[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))'; | |
my $regexp = qr/$pattern/; | |
my $regexp_o = qr/$pattern/o; | |
my $ipv4 = '192.168.1.1'; | |
cmpthese(0, +{ | |
'precompile' => sub { | |
$ipv4 =~ $regexp; | |
}, | |
'precompile_o' => sub { | |
$ipv4 =~ $regexp_o; | |
}, | |
'runtime' => sub { | |
$ipv4 =~ /$pattern/; | |
}, | |
'runtime_optimized' => sub { | |
$ipv4 =~ /$pattern/o; | |
}, | |
'runtime_static' => sub { | |
$ipv4 =~ /((?:(?:$h[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))/; | |
}, | |
'runtime_static_o' => sub { | |
$ipv4 =~ /((?:(?:$h[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))/o; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
正規表現周りのパフォチューだと
みたいな感じで、precompile(できれば) とか /o(付けられれば) とかは
なんかもう最後の一押し的な感じですかねえ
文字列の存在見るだけなら正規表現じゃなくて
index
でやろうとかもあるか