Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Plugins für Perl-Regexes

Renee
October 27, 2013

Plugins für Perl-Regexes

In bestimmten Fällen werden Perl-Regexes extrem langsam. Wenn man nicht alle Fähigkeiten der Perl-Regexes benötigt, kann eine andere Regex-Engine schneller sein. Dank der Plugin-Architektur ist es möglich die Perl-Regex-Engine in einem bestimmten Bereich durch eine andere Engine (z.B. RE2) zu ersetzen.

Renee

October 27, 2013
Tweet

More Decks by Renee

Other Decks in Programming

Transcript

  1. $ cat regex.pl !/usr/bin/perl use strict; use warnings; use Time::HiRes

    qw(time); use feature 'say'; my $count = $ARGV[0]; my $string = 'a' x $count; my $regex = ( 'a?' x $count ) . $string; my $time = time; $string =~ /$regex/; say "$count ($string)\n", time - $time;
  2. $ plenv exec-all perl regex.pl 3 5.14.0 ========== 3 (aaa)

    1.28746032714844e-05 5.18.0 ========== 3 (aaa) 1.28746032714844e-05 5.19.5 ========== 3 (aaa) 1.81198120117188e-05 $ plenv exec-all perl regex.pl 15 5.14.0 ========== 15 (aaaaaaaaaaaaaaa) 0.00228500366210938 5.18.0 ========== 15 (aaaaaaaaaaaaaaa) 0.00295805931091309 5.19.5 ========== 15 (aaaaaaaaaaaaaaa) 0.00253605842590332
  3. $ plenv exec-all perl regex.pl 25 5.14.0 ========== 25 (aaaaaaaaaaaaaaaaaaaaaaaaa)

    1.94273495674133 5.18.0 ========== 25 (aaaaaaaaaaaaaaaaaaaaaaaaa) 1.90621995925903 5.19.5 ========== 25 (aaaaaaaaaaaaaaaaaaaaaaaaa) 2.10874104499817 $ plenv exec-all perl regex.pl 29 5.14.0 ========== 29 (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa) 31.006912946701 5.18.0 ========== 29 (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa) 31.449235200882 5.19.5 ========== 29 (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa) 35.083554983139
  4. $ cat regex_re2.pl #!/usr/bin/perl use strict; use warnings; use Time::HiRes

    qw(time); use re::engine::RE2; use feature 'say'; my $count = $ARGV[0]; my $string = 'a' x $count; my $regex = ( 'a?' x $count ) . $string; my $time = time; $string =~ /$regex/; say "$count ($string)\n", time - $time;
  5. $ plenv exec-all perl regex_re2.pl 25 5.14.0 ========== 25 (aaaaaaaaaaaaaaaaaaaaaaaaa)

    0.000463008880615234 5.18.0 ========== 25 (aaaaaaaaaaaaaaaaaaaaaaaaa) 0.000398874282836914 5.19.5 ========== Can't locate re/engine/RE2.pm $ plenv exec-all perl regex_re2.pl 29 5.14.0 ========== 29 (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa) 0.000368833541870117 5.18.0 ========== 29 (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa) 0.000336885452270508 5.19.5 ========== Can't locate re/engine/RE2.pm