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

Strat
 2003-11-08 01:20
#70011 #70011
User since
2003-08-04
5246 Artikel
ModeratorIn
[Homepage] [default_avatar]
[quote=pq,07.11.2003, 22:06][/quote]
wie sieht eigentlich folgender Code aus?
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
use Benchmark;
$s=($" x 1000)."test";
sub a { $_=$s;s/^ +//; }
sub b { $_=$s;while(index($_, " ") == 0) { $_ = substr($_, 1) }}
sub c { $_=$s;
while (1) { $last = index($_, " ", $pos);
$last > -1 and $pos = $last+1;
$last == -1 and last;
} substr($_, 0, $pos) = "";
} # c

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

Code: (dl )
1
2
3
4
5
6
Benchmark: timing 10000 iterations of a, b, c...
a: 0 wallclock secs ( 0.03 usr + 0.00 sys = 0.03 CPU) @ 312500.00/s (n=10000)
(warning: too few iterations for a reliable count)
b: 9 wallclock secs ( 8.50 usr + 0.00 sys = 8.50 CPU) @ 1176.47/s (n=10000)
c: 0 wallclock secs ( 0.03 usr + 0.00 sys = 0.03 CPU) @ 322580.65/s (n=10000)
(warning: too few iterations for a reliable count)
perl -le "s::*erlco'unaty.'.dk':e,y;*kn:ai;penmic;;print"
http://www.fabiani.net/

View full thread Arbeiten mit Strings: Entfernung von Leerzeichen