Efektivita

Honza Pazdziora adelton na informatics.muni.cz
Čtvrtek Leden 21 12:27:17 MET 1999


> >
> >	$string =~ s/\s+$//;
> 
> tohle ale vypusti mezeru, at je na kraji nebo uprostred, ne?
> 
> Tobyasitentextnevypadalmochezky...

Ne, jak uz poznamenali jini. Ja jen dodam, ze uplne nejjednodussi je
si to vyzkouset. Jinak abych demostroval, ze \s+ je opravdu rychlejsi
nez while ...:

$ perl
use Benchmark;
timethese(50000, {
        's' => sub { my $a = 'Malicky krtecek   '; $a =~ s/\s+$//; },
        'ws' => sub { my $a = 'Malicky krtecek   '; while ($a =~ s/\s$//) {}; },
        });
__END__
Benchmark: timing 50000 iterations of s, ws...
         s:  6 secs ( 4.30 usr  0.02 sys =  4.32 cpu)
        ws: 10 secs ( 8.57 usr  0.04 sys =  8.61 cpu)

------------------------------------------------------------------------
 Honza Pazdziora | adelton na fi.muni.cz | http://www.fi.muni.cz/~adelton/
 The total number of bytes in all expressions in the GROUP BY clause is
 limited to the size of a data block minus some overhead. --Oracle SQL Ref.
------------------------------------------------------------------------


Další informace o konferenci Perl