3 Benchmark - benchmark running times of code
5 timethis - run a chunk of code several times
7 timethese - run several chunks of code several times
9 timeit - run a chunk of code and see how long it goes
13 timethis ($count, "code");
16 'Name1' => '...code1...',
17 'Name2' => '...code2...',
20 $t = timeit($count, '...other code...')
21 print "$count loops of other code took:",timestr($t),"\n";
25 The Benchmark module encapsulates a number of routines to help you
26 figure out how long it takes to execute some code.
34 Returns the current time. Example:
38 # ... your code here ...
40 $td = timediff($t1, $t0);
41 print "the code took:",timestr($dt),"\n";
45 Enables or disable debugging by setting the C<$Benchmark::Debug> flag:
48 $t = timeit(10, ' 5 ** $Global ');
53 =head2 Standard Exports
55 The following routines will be exported into your namespace
56 if you use the Benchmark module:
60 =item timeit(COUNT, CODE)
62 Arguments: COUNT is the number of time to run the loop, and
63 the second is the code to run. CODE may be a string containing the code,
64 a reference to the function to run, or a reference to a hash containing
65 keys which are names and values which are more CODE specs.
67 Side-effects: prints out noise to standard out.
69 Returns: a Benchmark object.
81 =head2 Optional Exports
83 The following routines will be exported into your namespace
84 if you specifically ask that they be imported:
100 The data is stored as a list of values from the time and times
103 ($real, $user, $system, $children_user, $children_system)
105 in seconds for the whole loop (not divided by the number of rounds).
107 The timing is done using time(3) and times(3).
109 Code is executed in the caller's package.
113 $Benchmark::debug = 1;
115 The time of the null loop (a loop with the same
116 number of rounds but empty loop body) is subtracted
117 from the time of the real loop.
119 The null loop times are cached, the key being the
120 number of rounds. The caching can be controlled using
131 Benchmark inherits from no other class, except of course
136 The real time timing is done using time(2) and
137 the granularity is therefore only one second.
139 Short tests may produce negative figures because perl
140 can appear to take longer to execute the empty loop
141 than a short test; try:
145 The system time of the null loop might be slightly
146 more than the system time of the loop with the actual
147 code and therefore the difference might end up being < 0.
149 More documentation is needed :-( especially for styles and formats.
153 Jarkko Hietaniemi <Jarkko.Hietaniemi@hut.fi>,
154 Tim Bunce <Tim.Bunce@ig.co.uk>
156 =head1 MODIFICATION HISTORY
158 September 8th, 1994; by Tim Bunce.