1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/perl
use Benchmark;
$rein = '+5000*';
timethese(10000000, {
A => sub {
if ($rein =~ m~(?:-|\+|\*|/)~) {
# Do nothing
}
},
B => sub {
if ($rein =~ m~-~ or m~\+~ or m~\*~ or m~/~) {
# Do nothing
}
},
C => sub {
if ($rein =~ m~[-+*/]~) {
# Do nothing
}
},
D => sub {
if ($rein =~ m~[-]~ or m~[+]~ or m~[*]~ or m~[/]~) {
# Do nothing
}
},
E => sub {
if (index($_, '-') > -1 or index($_, '+') > -1 or index($_, '*') > -1 or index($_, '/') > -1) {
# Do nothing
}
}
});
Benchmark: timing 1000000 iterations of A, B, C, D, E...
A: 1 wallclock secs ( 0.80 usr + 0.00 sys = 0.80 CPU) @ 1246882.79/s
B: 1 wallclock secs ( 1.07 usr + 0.00 sys = 1.07 CPU) @ 932835.820/s
C: 1 wallclock secs ( 0.64 usr + 0.00 sys = 0.64 CPU) @ 1562500.00/s
D: 1 wallclock secs ( 0.95 usr + -0.01 sys = 0.94 CPU) @ 1063829.79/s
E: 2 wallclock secs ( 1.45 usr + 0.00 sys = 1.45 CPU) @ 688705.230/s
Windows 2000SP3
1,4 GHZ
1024 MB RAM
Wir sehen:
Die Indexmethode ist diesmal
nicht schneller,
der Rest ist relativ gleich. C is am schnellsten.
Die meisten PC Probleme befinden sich zwischen Bildschirm und Stuhl...