4 Einträge, 1 Seite |
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!perl -w
my $str = '';
open( FH, "<test.htm") or die("Cannot open file");
while(<FH>)
{
$str .= $_;
}
close(FH);
$length = length($str);
print "Str-Laenge: $length\n";
# start timer
$start = time();
# perform a math operation 200000 times
for ($x=0; $x<=1000000; $x++)
{
### Operations
&test2;
}
# end timer
$end = time();
# report
print "Time taken was ", ($end - $start), " seconds";
sub test1()
{
my $start = index($str, "<title>");
my $ende = index($str, "</title>");
$ende = $ende - $start - 7;
$start += 7;
my $title = substr($str, $start, $ende);
}
sub test2()
{
if($str =~ /<title>(.*)<\/title>/i )
{
my $title = $1;
}
}
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
#!/usr/bin/perl use strict; use warnings; use Benchmark; # test.html beinhaltet diese Beitragsseite lokal gespeichert open FH, "test.html" or die "test.html: $!"; my $string = do { local $/; <FH> }; close FH; timethese (1_000_000, { func1 => \&func1, func2 => \&func2, }); sub func1 { my $start = index($string, "<title>"); my $ende = index($string, "</title>"); my $title = substr($string, $start+7, $ende - $start - 7); } sub func2 { my $title = Å© if ( $string =~ m{<title>(.*)</title>}i ) ; }
QuoteBenchmark: timing 1000000 iterations of func1, func2...
func1: 1 wallclock secs ( 1.76 usr + 0.00 sys = 1.76 CPU) @ 568181.82/s (n=1000000)
func2: 15 wallclock secs (14.47 usr + 0.00 sys = 14.47 CPU) @ 69108.50/s (n=1000000)
QuoteBenchmark: timing 1000000 iterations of func1, func2...
func1: 28 wallclock secs ( 3.44 usr + 2.70 sys = 6.14 CPU) @ 162866.45/s (n=1000000)
func2: 45 wallclock secs (18.82 usr + 3.27 sys = 22.09 CPU) @ 45269.35/s (n=1000000)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/usr/bin/perl use strict; use warnings; use Benchmark; open FH, "test.html" or die "test.html: $!"; my $string = do { local $/; <FH> }; close FH; timethese (1_000_000, { func1 => \&func1, func2 => \&func2, }); sub func1 { my $start = index($string, "<title>"); my $ende = index($string, "</title>"); print STDERR substr($string, $start+7, $ende - $start - 7); } sub func2 { print STDERR Å© if ( $string =~ m{<title>(.*)</title>} ) ; }
Quoteperl perl03 1>result.txt
4 Einträge, 1 Seite |