Thread Arbeiten mit Strings: Entfernung von Leerzeichen (12 answers)
Opened by Gast at 2003-11-07 09:04

pq
 2003-11-07 23:06
#70010 #70010
User since
2003-08-04
12209 Artikel
Admin1
[Homepage]
user image
[quote=havi,07.11.2003, 18:46]
Code: (dl )
1
2
3
Benchmark: timing 1000000 iterations of index, regex...
    index:  2 wallclock secs ( 1.30 usr +  0.00 sys =  1.30 CPU) @ 771010.02/s (n=1000000)
    regex:  2 wallclock secs ( 1.09 usr +  0.00 sys =  1.09 CPU) @ 913242.01/s (n=1000000)
[/quote]
@havi: mit welchem code hast du denn das ergebnis gekriegt?
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use Benchmark;
$s=($" x 1000)."test";
sub a { $_=$s;s/^ +//; }
sub b { $_=$s;while(index($_, " ") == 0) { $_ = substr($_, 1) }}

timethese(10000, {a=>\&a,b=>\&b});

Ergebnis:
Benchmark:
timing 10000 iterations of
a, b
...

        a:  0 wallclock secs ( 0.06 usr +  0.00 sys =  0.06 CPU) @ 166666.67/s (n=10000)

           (warning: too few iterations for a reliable count)

        b: 10 wallclock secs ( 9.18 usr +  0.00 sys =  9.18 CPU) @ 1089.32/s (n=10000)
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem

View full thread Arbeiten mit Strings: Entfernung von Leerzeichen