Schrift
[thread]8908[/thread]

Regexes: Geschwindigkeitsoptimierung (Seite 2)



<< |< 1 2 >| >> 14 Einträge, 2 Seiten
PerlProfi
 2007-04-08 22:25
#75729 #75729
User since
2006-11-29
340 Artikel
BenutzerIn
[default_avatar]
@opi, ja sorry wegen des modifiers, ich hatte einfach die regexp von goodfella genommen und in qr// geschrieben.

Allerdings sollte mein Kommentar direkt darüber deutlich machen, das diese Zuweisung irgendwo steht, wo sie eben nicht sehr oft aufgerufen wird.
Und so wie ich es verstanden habe, sollte das in goodfellas code möglich sein.

MfG\n\n

<!--EDIT|PerlProfi|1176056789-->
bloonix
 2007-04-08 22:32
#75730 #75730
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
[quote=PerlProfi,08.04.2007, 20:25]@opi, ja sorry wegen des modifiers, ich hatte einfach die regexp von goodfella genommen und in qr// geschrieben.[/quote]
kein problem... sowas hatte ich mir schon gedacht. :)

@GoodFella... ich möchte noch was hinzufügen...

Mit "ausserhalb der Schleife definieren" meinte ich nicht, dass man jede
einzelne Regex ausserhalb definieren soll. Sowas hier geht natürlich
auch:

Code: (dl )
1
2
3
4
5
   my $rx = /\d+/;

  for (0..100000) {
     'foo 1 bar' =~ /foo $rx bar/o;
  }


und

Code: (dl )
1
2
3
4
5
sub rx_best {
  for (0..100000) {
     1 =~ /\d+/;
  }
}


bleibt unschlagbar ;)\n\n

<!--EDIT|opi|1176074164-->
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.
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-->
bloonix
 2007-04-09 22:22
#75732 #75732
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
[quote=GoodFella,09.04.2007, 14:26]ich frage mich, warum mein Beispiel vorher in dem Thread so realitätsferne Ergenisse geliefert hat..[/quote]
Warum Realitätsfremd. Mit qr// wird halt auf ein Objekt zuge-
griffen, was die Regex ein wenig verlangsamt... so ist das halt :)
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.
<< |< 1 2 >| >> 14 Einträge, 2 Seiten



View all threads created 2007-04-06 19:31.