Thread Regexes: Geschwindigkeitsoptimierung
(13 answers)
Opened by GoodFella at 2007-04-06 19:31
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 ..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--> |