Last active
August 29, 2015 14:16
-
-
Save i110/28abb5692ee1ed2bbb0a 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 feature 'say'; | |
use Benchmark qw(cmpthese); | |
say $]; | |
my $pattern = '((?:(?:25[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 $ipv4 = '192.168.1.1'; | |
cmpthese(0, +{ | |
'reref_expand_pattern' => sub { | |
$ipv4 =~ qr/$pattern/; | |
}, | |
'reref_static' => sub { | |
$ipv4 =~ qr/((?:(?:25[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]?))/; | |
}, | |
'expand_reref' => sub { | |
$ipv4 =~ /$regexp/; | |
}, | |
'precompile' => sub { | |
$ipv4 =~ $regexp; | |
}, | |
'expand_pattern' => sub { | |
$ipv4 =~ /$pattern/; | |
}, | |
'static' => sub { | |
$ipv4 =~ /((?:(?:25[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]?))/; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ふと思い立って色んな長さのパターンで試してみた
5倍の長さ(上記パターンの5回繰り返し)
ipv4の最初の数字のみ /(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/
1文字のみ /1/
全方位的にベタ書き最強でしたとさ。