Created
March 1, 2015 03:48
-
-
Save i110/901b94e7a86911c31930 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, +{ | |
'precompile' => sub { | |
$ipv4 =~ $regexp; | |
}, | |
'runtime' => sub { | |
$ipv4 =~ /$pattern/; | |
}, | |
'runtime_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]?))/; | |
}, | |
}); |
- 観察
- バージョンによらず、precompile < runtime < runtime_staticの順であることには変わりないらしい
- しかもそれなりに無視できない差がついているらしい
- 何故かはわからない
- 示唆
- 静的な奴:何も考えずに直書きしとけ
- 動的な奴:変数化が必要でない時は何も考えずにそのまま変数展開しとけ
今までパフォーマンスのために頑張ってprecompileしてきたのはなんだったんや…\(^o^)/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
5.16.3
5.21.9