Leser: 1
|< 1 2 >| | 13 Einträge, 2 Seiten |
QuoteIch bin mir aber nicht sicher, ob du das weißt!
1
2
3
4
5
6
7
8
9
10
C:\Dokumente und Einstellungen\jan>perl
use Benchmark qw/:all/;
timethese(10000000, {
'regexp' => sub { my $var = '1555000000'; my $onlydigits = 1 if($var =~ m/^\d$/);},
'inttest' => sub { my $var = '1555000000'; my $onlydigits = 1 if(int($var) eq $var);},
});
^Z
Benchmark: timing 10000000 iterations of inttest, regexp...
inttest: 19 wallclock secs (17.57 usr + 0.01 sys = 17.58 CPU) @ 568957.67/s (n=10000000)
regexp: 8 wallclock secs ( 6.84 usr + 0.03 sys = 6.87 CPU) @ 1455604.08/s (n=10000000)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
~/perl/test> cat nurzahlen.pl
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark qw/cmpthese/;
cmpthese(-5, {
regexpZiffer => sub { my $var = '1555000000'; my $onlydigits = 1 if($var =~ m/^\d$/);},
regexpStern => sub { my $var = '1555000000'; my $onlydigits = 1 if($var =~ m/^\d*$/);},
regexpPlus => sub { my $var = '1555000000'; my $onlydigits = 1 if($var =~ m/^\d+$/);},
regexpInv => sub { my $var = '1555000000'; my $onlydigits = 1 unless ($var =~ m/\D/);},
inttest => sub { my $var = '1555000000'; my $onlydigits = 1 if(int($var) eq $var);},
});
~/perl/test> ./nurzahlen.pl
Rate regexpStern regexpPlus inttest regexpInv regexpZiffer
regexpStern 1049899/s -- -2% -4% -28% -37%
regexpPlus 1069469/s 2% -- -2% -27% -36%
inttest 1096502/s 4% 3% -- -25% -35%
regexpInv 1459240/s 39% 36% 33% -- -13%
regexpZiffer 1678905/s 60% 57% 53% 15% --
|< 1 2 >| | 13 Einträge, 2 Seiten |