@@ -5,13 +5,13 @@ use strict;
55
66=head1 NAME
77
8- Benchmark - benchmark running times of Perl code
8+ Benchmark - Benchmark running times of Perl code
99
1010=head1 SYNOPSIS
1111
12- use Benchmark qw(:all) ;
12+ use Benchmark qw(:all);
1313
14- timethis ($count, "code");
14+ timethis($count, "code");
1515
1616 # Use Perl code in strings...
1717 timethese($count, {
@@ -44,32 +44,32 @@ Benchmark - benchmark running times of Perl code
4444 },
4545 'none'
4646 );
47- cmpthese( $results ) ;
47+ cmpthese( $results );
4848
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";
5151
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";
5555
56- # enable hires wallclock timing if possible
56+ # Enable hires wallclock timing if possible
5757 use Benchmark ':hireswallclock';
5858
5959=head1 DESCRIPTION
6060
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.
6363
64- timethis - run a chunk of code several times
64+ C< timethis > - Run a chunk of code several times
6565
66- timethese - run several chunks of code several times
66+ C< timethese > - Run several chunks of code several times
6767
68- cmpthese - print results of timethese as a comparison chart
68+ C< cmpthese > - Print results of C< timethese > as a comparison chart
6969
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
7171
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
7373
7474
7575=head2 Methods
@@ -81,18 +81,18 @@ countit - see how many times a chunk of code runs in a given time
8181Returns the current time. Example:
8282
8383 use Benchmark;
84- $t0 = Benchmark->new;
84+ my $t0 = Benchmark->new;
8585 # ... your code here ...
86- $t1 = Benchmark->new;
87- $td = timediff($t1, $t0);
86+ my $t1 = Benchmark->new;
87+ my $td = timediff($t1, $t0);
8888 print "the code took:",timestr($td),"\n";
8989
9090=item debug
9191
9292Enables or disable debugging by setting the C<$Benchmark::Debug > flag:
9393
9494 Benchmark->debug(1);
95- $t = timeit(10, ' 5 ** $Global ');
95+ my $t = timeit(10, ' 5 ** $Global ');
9696 Benchmark->debug(0);
9797
9898=item iters
@@ -128,11 +128,11 @@ The COUNT can be zero or negative: this means the I<minimum number of
128128CPU seconds> to run. A zero signifies the default of 3 seconds. For
129129example to run at least for 10 seconds:
130130
131- timethis(-10, $code)
131+ timethis(-10, $code);
132132
133133or to run two pieces of code tests for at least 3 seconds:
134134
135- timethese(0, { test1 => '...', test2 => '...'})
135+ timethese(0, { test1 => '...', test2 => '...'});
136136
137137CPU seconds is, in UNIX terms, the user time plus the system time of
138138the 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.
155155For each (KEY, VALUE) pair in the CODEHASHREF, this routine will
156156call
157157
158- timethis(COUNT, VALUE, KEY, STYLE)
158+ timethis(COUNT, VALUE, KEY, STYLE);
159159
160160The routines are called in string comparison order of KEY.
161161
@@ -208,7 +208,7 @@ Clear all cached times.
208208
209209Optionally calls timethese(), then outputs comparison chart. This:
210210
211- cmpthese( -1, { a => "++\$i", b => "\$i *= 2" } ) ;
211+ cmpthese( -1, { a => "++\$i", b => "\$i *= 2" } );
212212
213213outputs a chart like:
214214
@@ -221,8 +221,8 @@ difference between each pair of tests.
221221
222222C<cmpthese > can also be passed the data structure that timethese() returns:
223223
224- $results = timethese( -1,
225- { a => "++\$i", b => "\$i *= 2" } ) ;
224+ my $results = timethese( -1,
225+ { a => "++\$i", b => "\$i *= 2" } );
226226 cmpthese( $results );
227227
228228in case you want to see both sets of results.
@@ -329,7 +329,7 @@ Number of iterations run.
329329
330330The following illustrates use of the Benchmark object:
331331
332- $result = timethis(100000, sub { ... });
332+ my $result = timethis(100000, sub { ... });
333333 print "total CPU = ", $result->cpu_a, "\n";
334334
335335=head1 NOTES
@@ -367,7 +367,7 @@ accuracy and does not usually noticeably affect runtimes.
367367For example,
368368
369369 use Benchmark qw( cmpthese ) ;
370- $x = 3;
370+ my $x = 3;
371371 cmpthese( -5, {
372372 a => sub{$x*$x},
373373 b => sub{$x**2},
@@ -384,8 +384,8 @@ outputs something like this:
384384while
385385
386386 use Benchmark qw( timethese cmpthese ) ;
387- $x = 3;
388- $r = timethese( -5, {
387+ my $x = 3;
388+ my $r = timethese( -5, {
389389 a => sub{$x*$x},
390390 b => sub{$x**2},
391391 } );
@@ -482,7 +482,7 @@ our(@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION);
482482 clearcache clearallcache disablecache enablecache) ;
483483%EXPORT_TAGS =( all => [ @EXPORT , @EXPORT_OK ] ) ;
484484
485- $VERSION = 1.25 ;
485+ $VERSION = 1.26 ;
486486
487487# --- ':hireswallclock' special handling
488488
0 commit comments