Skip to content

Instantly share code, notes, and snippets.

@i110
Last active August 29, 2015 14:16
Show Gist options
  • Save i110/bc8ca9d68ad9da62001a to your computer and use it in GitHub Desktop.
Save i110/bc8ca9d68ad9da62001a to your computer and use it in GitHub Desktop.
なんでだろ〜なんでだろ〜
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Benchmark qw(cmpthese);
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_optimized' => sub {
$ipv4 =~ /$pattern/o;
},
'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]?))/;
},
});
# Rate precompile runtime runtime_optimized runtime_static
# precompile 939495/s -- -28% -32% -35%
# runtime 1313724/s 40% -- -4% -8%
# runtime_optimized 1372723/s 46% 4% -- -4%
# runtime_static 1435474/s 53% 9% 5% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment