Thread Optimierung eines Programms (35 answers)
Opened by Jan at 2014-12-19 09:34

pq
 2014-12-19 12:48
#178820 #178820
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
my $text = "foo";
sub SUBSTR {
    my $c = substr $text, 0, 1;
    return ( $c eq "*" or $c eq " " or $c eq "\t" or $c eq "\r" or $c eq "\n" );
}
sub REGEX {
    return ($text =~ m/^\*/ || $text =~ m/^\s+/);
}
use Benchmark;
timethese(5000000, { substr => \&SUBSTR, regex => \&REGEX })
__END__
Benchmark: timing 5000000 iterations of regex, substr...
     regex:  2 wallclock secs ( 1.07 usr +  0.00 sys =  1.07 CPU) @ 4672897.20/s (n=5000000)
    substr:  1 wallclock secs ( 1.38 usr +  0.00 sys =  1.38 CPU) @ 3623188.41/s (n=5000000)

Last edited: 2014-12-19 12:49:44 +0100 (CET)
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem

View full thread Optimierung eines Programms