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

5.16.3

                    Rate     precompile        runtime runtime_static
precompile      782945/s             --           -17%           -24%
runtime         945888/s            21%             --            -8%
runtime_static 1026324/s            31%             9%             --

                    Rate     precompile        runtime runtime_static
precompile      769352/s             --           -23%           -30%
runtime        1000446/s            30%             --            -9%
runtime_static 1097473/s            43%            10%             --

                    Rate     precompile        runtime runtime_static
precompile      794062/s             --           -21%           -28%
runtime        1000842/s            26%             --            -9%
runtime_static 1105020/s            39%            10%             --

                    Rate     precompile        runtime runtime_static
precompile      794430/s             --           -25%           -29%
runtime        1053768/s            33%             --            -5%
runtime_static 1111969/s            40%             6%             --

                    Rate     precompile runtime_static        runtime
precompile      810255/s             --           -24%           -24%
runtime_static 1061161/s            31%             --            -1%
runtime        1067288/s            32%             1%             --

5.21.9

                   Rate runtime_static     precompile        runtime
runtime        574337/s             --            -9%           -13%
precompile     634119/s            10%             --            -4%
runtime_static 660602/s            15%             4%             --

                   Rate     precompile runtime_static        runtime
precompile     723496/s             --           -19%           -22%
runtime_static 893243/s            23%             --            -3%
runtime        925633/s            28%             4%             --

                   Rate     precompile        runtime runtime_static
precompile     679789/s             --           -19%           -31%
runtime        839122/s            23%             --           -15%
runtime_static 981911/s            44%            17%             --

                   Rate     precompile        runtime runtime_static
precompile     691419/s             --           -15%           -26%
runtime        814058/s            18%             --           -12%
runtime_static 928624/s            34%            14%             --

                   Rate     precompile        runtime runtime_static
precompile     675264/s             --           -22%           -30%
runtime        863598/s            28%             --           -11%
runtime_static 966792/s            43%            12%             --

@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