Leser: 3
|< 1 2 >| | 13 Einträge, 2 Seiten |
s!^ +!!;
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)
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)
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} );
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)
|< 1 2 >| | 13 Einträge, 2 Seiten |