@@ -5,13 +5,13 @@ use strict;
5
5
6
6
=head1 NAME
7
7
8
- Benchmark - benchmark running times of Perl code
8
+ Benchmark - Benchmark running times of Perl code
9
9
10
10
=head1 SYNOPSIS
11
11
12
- use Benchmark qw(:all) ;
12
+ use Benchmark qw(:all);
13
13
14
- timethis ($count, "code");
14
+ timethis($count, "code");
15
15
16
16
# Use Perl code in strings...
17
17
timethese($count, {
@@ -44,32 +44,32 @@ Benchmark - benchmark running times of Perl code
44
44
},
45
45
'none'
46
46
);
47
- cmpthese( $results ) ;
47
+ cmpthese( $results );
48
48
49
- $t = timeit($count, '...other code...')
50
- print "$count loops of other code took:",timestr($t ),"\n";
49
+ my $t1 = timeit($count, '...other code...');
50
+ print "$count loops of other code took:", timestr($t1 ),"\n";
51
51
52
- $t = countit($time, '...other code...')
53
- $count = $t ->iters ;
54
- print "$count loops of other code took:",timestr($t ),"\n";
52
+ my $t2 = countit($time, '...other code...');
53
+ $count = $t2 ->iters;
54
+ print "$count loops of other code took:", timestr($t2 ),"\n";
55
55
56
- # enable hires wallclock timing if possible
56
+ # Enable hires wallclock timing if possible
57
57
use Benchmark ':hireswallclock';
58
58
59
59
=head1 DESCRIPTION
60
60
61
- The Benchmark module encapsulates a number of routines to help you
62
- figure out how long it takes to execute some code.
61
+ The C< Benchmark > module encapsulates a number of routines to
62
+ help you figure out how long it takes to execute some code.
63
63
64
- timethis - run a chunk of code several times
64
+ C< timethis > - Run a chunk of code several times
65
65
66
- timethese - run several chunks of code several times
66
+ C< timethese > - Run several chunks of code several times
67
67
68
- cmpthese - print results of timethese as a comparison chart
68
+ C< cmpthese > - Print results of C< timethese > as a comparison chart
69
69
70
- timeit - run a chunk of code and see how long it goes
70
+ C< timeit > - Run a chunk of code and see how long it goes
71
71
72
- countit - see how many times a chunk of code runs in a given time
72
+ C< countit > - See how many times a chunk of code runs in a given time
73
73
74
74
75
75
=head2 Methods
@@ -81,18 +81,18 @@ countit - see how many times a chunk of code runs in a given time
81
81
Returns the current time. Example:
82
82
83
83
use Benchmark;
84
- $t0 = Benchmark->new;
84
+ my $t0 = Benchmark->new;
85
85
# ... your code here ...
86
- $t1 = Benchmark->new;
87
- $td = timediff($t1, $t0);
86
+ my $t1 = Benchmark->new;
87
+ my $td = timediff($t1, $t0);
88
88
print "the code took:",timestr($td),"\n";
89
89
90
90
=item debug
91
91
92
92
Enables or disable debugging by setting the C<$Benchmark::Debug > flag:
93
93
94
94
Benchmark->debug(1);
95
- $t = timeit(10, ' 5 ** $Global ');
95
+ my $t = timeit(10, ' 5 ** $Global ');
96
96
Benchmark->debug(0);
97
97
98
98
=item iters
@@ -128,11 +128,11 @@ The COUNT can be zero or negative: this means the I<minimum number of
128
128
CPU seconds> to run. A zero signifies the default of 3 seconds. For
129
129
example to run at least for 10 seconds:
130
130
131
- timethis(-10, $code)
131
+ timethis(-10, $code);
132
132
133
133
or to run two pieces of code tests for at least 3 seconds:
134
134
135
- timethese(0, { test1 => '...', test2 => '...'})
135
+ timethese(0, { test1 => '...', test2 => '...'});
136
136
137
137
CPU seconds is, in UNIX terms, the user time plus the system time of
138
138
the process itself, as opposed to the real (wallclock) time and the
@@ -155,7 +155,7 @@ and either a string to eval or a code reference for each value.
155
155
For each (KEY, VALUE) pair in the CODEHASHREF, this routine will
156
156
call
157
157
158
- timethis(COUNT, VALUE, KEY, STYLE)
158
+ timethis(COUNT, VALUE, KEY, STYLE);
159
159
160
160
The routines are called in string comparison order of KEY.
161
161
@@ -208,7 +208,7 @@ Clear all cached times.
208
208
209
209
Optionally calls timethese(), then outputs comparison chart. This:
210
210
211
- cmpthese( -1, { a => "++\$i", b => "\$i *= 2" } ) ;
211
+ cmpthese( -1, { a => "++\$i", b => "\$i *= 2" } );
212
212
213
213
outputs a chart like:
214
214
@@ -221,8 +221,8 @@ difference between each pair of tests.
221
221
222
222
C<cmpthese > can also be passed the data structure that timethese() returns:
223
223
224
- $results = timethese( -1,
225
- { a => "++\$i", b => "\$i *= 2" } ) ;
224
+ my $results = timethese( -1,
225
+ { a => "++\$i", b => "\$i *= 2" } );
226
226
cmpthese( $results );
227
227
228
228
in case you want to see both sets of results.
@@ -329,7 +329,7 @@ Number of iterations run.
329
329
330
330
The following illustrates use of the Benchmark object:
331
331
332
- $result = timethis(100000, sub { ... });
332
+ my $result = timethis(100000, sub { ... });
333
333
print "total CPU = ", $result->cpu_a, "\n";
334
334
335
335
=head1 NOTES
@@ -367,7 +367,7 @@ accuracy and does not usually noticeably affect runtimes.
367
367
For example,
368
368
369
369
use Benchmark qw( cmpthese ) ;
370
- $x = 3;
370
+ my $x = 3;
371
371
cmpthese( -5, {
372
372
a => sub{$x*$x},
373
373
b => sub{$x**2},
@@ -384,8 +384,8 @@ outputs something like this:
384
384
while
385
385
386
386
use Benchmark qw( timethese cmpthese ) ;
387
- $x = 3;
388
- $r = timethese( -5, {
387
+ my $x = 3;
388
+ my $r = timethese( -5, {
389
389
a => sub{$x*$x},
390
390
b => sub{$x**2},
391
391
} );
@@ -482,7 +482,7 @@ our(@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION);
482
482
clearcache clearallcache disablecache enablecache) ;
483
483
%EXPORT_TAGS =( all => [ @EXPORT , @EXPORT_OK ] ) ;
484
484
485
- $VERSION = 1.25 ;
485
+ $VERSION = 1.26 ;
486
486
487
487
# --- ':hireswallclock' special handling
488
488
0 commit comments