Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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% --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement