[quote=pq,07.11.2003, 22:06][/quote]
wie sieht eigentlich folgender Code aus?
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} );
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)