Skip to content

Instantly share code, notes, and snippets.

@i110
Created March 1, 2015 03:48
Show Gist options
  • Save i110/901b94e7a86911c31930 to your computer and use it in GitHub Desktop.
Save i110/901b94e7a86911c31930 to your computer and use it in GitHub Desktop.
バージョン別
#!/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]?))/;
},
});
@i110
Copy link
Author

i110 commented Mar 1, 2015

  • 観察
    • バージョンによらず、precompile < runtime < runtime_staticの順であることには変わりないらしい
    • しかもそれなりに無視できない差がついているらしい
    • 何故かはわからない
  • 示唆
    • 静的な奴:何も考えずに直書きしとけ
    • 動的な奴:変数化が必要でない時は何も考えずにそのまま変数展開しとけ

今までパフォーマンスのために頑張ってprecompileしてきたのはなんだったんや…\(^o^)/

@i110
Copy link
Author

i110 commented Mar 1, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment