Book HomeJava and XSLTSearch this book

8.25. Benchmark

Provides routines for timing the execution of your code and formatting the results. Inherits only from the Exporter class. It has the following functions.

new

new Benchmark

Returns the current time. By getting the current time before and after running the code, you can calculate the time it takes the code to run.

clearallcache

clearallcache

Clears the entire cache. Exported on request.

clearcache

clearcache (count)

Clears the cached time for count rounds of the null loop. Exported on request.

debug

Benchmark->debug(flag)

Enables or disables debugging by setting the $Benchmark::Debug flag.

disablecache

disablecache

Disables use of the cache. Exported on request.

enablecache

enablecache

Resumes caching. Exported on request.

timediff

timediff (t1, t2)

Calculates the difference between two times and returns the difference as a Benchmark object suitable for passing to timestr. Always exported.

timeit

timeit (count, code)

Runs code and reports the time it took. Always exported. Takes the following arguments:

count
The number of times to run the loop

code
The code to run, specified as either a code reference or a string

timestr

timestr (timediff[, style[, format]])

Converts times to printable strings. Always exported. Takes the following arguments:

timediff
The object containing the times to be formatted.

style
The output format. The possible values of style are:

all
Shows all of the following times: wallclock, user, system, user time of children, and system time of children

auto
Like all, except that if the children times are both 0, it acts like noc

noc
Shows all except the two children times

nop
Shows only wallclock and the two children times

format
Indicates the printf(3)-style format specifier (without the leading %) to use for printing the times. The default is 5.2f.

timethese

timethese (count, \%codehashref[, style])

Times each of several pieces of code and reports the results separately. Always exported. Takes the following arguments:

count
The number of times to run the loop.

\%codehashref
Reference to a hash in which the keys are names and the values are either strings or code references; each key/value pair specifies a piece of code to run.

style
Determines the format of the output. See timestr for the possible values of style.

timethis

timethis (count, code[, title[, style]])

Runs a chunk of code several times. Always exported. Takes the following arguments:

count
The number of times to run the loop.

code
The code to run, specified as either a code reference or a string.

title
The title of the result; default is "timethis COUNT".

style
Determines the format of the output. See timestr for the possible values of style.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.