Thread Regexes: Geschwindigkeitsoptimierung (13 answers)
Opened by GoodFella at 2007-04-06 19:31

GoodFella
 2007-04-09 16:26
#75731 #75731
User since
2007-01-09
192 Artikel
BenutzerIn
[default_avatar]
Danke für Deine Mühe, opi; ich habe deiner Testreihe noch etwas hinzugefügt:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark;

Benchmark::cmpthese(-1, {
  bad_1 => \&rx_bad_1,
  bad_2 => \&rx_bad_2,
  good  => \&rx_good,
  good_2  => \&rx_good_2,
  good_3  => \&rx_good_3,
  good_4  => \&rx_good_4
});

sub rx_bad_1 {  for (0..100000) { my $rx = qr/\d+/o; 1 =~ /$rx/; } }
sub rx_bad_2 {  for (0..100000) { my $rx = qr/\d+/;  1 =~ /$rx/o; } }
sub rx_good {   my $rx = qr/\d+/; for (0..100000) { 1 =~ /$rx/o; } }
sub rx_good_2 { my $rx = qr/\d+/; for (0..100000) { 1 =~ /$rx/; } }
sub rx_good_3 { my $rx = '\d+';   for (0..100000) { 1 =~ /$rx/o; } }
sub rx_good_4 { my $rx = '\d+';   for (0..100000) { 1 =~ /$rx/; } }


ergibt

Quote
        Rate  bad_1  bad_2 good_2 good_4   good good_3
bad_1  2.18/s     --    -6%   -84%   -86%   -88%   -88%
bad_2  2.31/s     6%     --   -83%   -85%   -87%   -87%
good_2 14.0/s   542%   505%     --    -8%   -21%   -21%
good_4 15.3/s   600%   560%     9%     --   -13%   -13%
good   17.6/s   708%   661%    26%    15%     --     0%
good_3 17.6/s   708%   661%    26%    15%     0%     --


..hast wohl die beste Methode gefunden.. ich frage mich, warum mein Beispiel vorher in dem Thread so realitätsferne Ergenisse geliefert hat.. schliesslich habe ich auch ausserhalb der "Schleife" defniniert (cmpthese ist doch eine Schleife, wenn man den ersten Parameter auf grösser als 1 setzt?!)\n\n

<!--EDIT|GoodFella|1176121601-->

View full thread Regexes: Geschwindigkeitsoptimierung