Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. use utf8;
  5. use Benchmark qw(cmpthese);
  6.  
  7. 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]?))';
  8. my $regexp = qr/$pattern/;
  9. my $ipv4 = '192.168.1.1';
  10. cmpthese(0, +{
  11. 'precompile' => sub {
  12. $ipv4 =~ $regexp;
  13. },
  14. 'runtime' => sub {
  15. $ipv4 =~ /$pattern/;
  16. },
  17. 'runtime_optimized' => sub {
  18. $ipv4 =~ /$pattern/o;
  19. },
  20. 'runtime_static' => sub {
  21. $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]?))/;
  22. },
  23. });
  24.  
  25. # Rate precompile runtime runtime_optimized runtime_static
  26. # precompile 939495/s -- -28% -32% -35%
  27. # runtime 1313724/s 40% -- -4% -8%
  28. # runtime_optimized 1372723/s 46% 4% -- -4%
  29. # runtime_static 1435474/s 53% 9% 5% --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement