bench
index
/home/slamb/www-projects-wc/bench/bench.py

Benchmarks a program or Python fragment: determines a confidence
interval for its mean user CPU, system CPU, and real time.
 
As a standalone executable, it benchmarks the program specified on the
commandline five times at a 95% confidence interval.
 
Copyright 2004 Scott Lamb <slamb@slamb.org>.
Released under the MIT license.
 
$Id: bench.py 935 2005-02-03 04:33:40Z slamb $

 
Modules
            
math
os
resource
sys
time
 
Classes
            
Sample
 
class Sample
      Tracks the mean and standard deviation of a sample.
 
Does not store the entire sample in memory; there is no need.
 
   Methods defined here:
__init__(self)
append(self, value)
Computes mean and standard deviation on-the-fly.
 
Algorithm from Knuth, The Art of Computer Programming, vol. 2,
p. 232. (Which in turn refers to B. P. Welford, Technometrics 4
(1962), 419-420.)
getConfidenceInterval(self, alpha=0.050000000000000003)
Returns a confidence interval for the mean value, in
(center, range) form.
 
See Miller and Miller, John E. Freund's Mathematical Statistics,
Sixth Edition, p. 364.
 
For now, only a very limited number of values for alpha and n are
supported, since calculating t_{\alpha,\nu} is non-trivial.
getMean(self)
getStddev(self)

Data and non-method functions defined here:
__doc__ = 'Tracks the mean and standard deviation of a samp...re the entire sample in memory; there is no need.'
__module__ = 'bench'
 
Functions
            
benchmark(run_group, n=5, alpha=0.050000000000000003, group_size=1)
Returns the user CPU, system CPU, and real time confidence intervals
for n runs of the program to be benchmarked.
 
run_group should be an executable object that takes no arguments and
returns a tuple containing user CPU, system CPU, and real time, in
seconds.  This tuple represents the total CPU usage of a group of
group_size iterations.  You would use a group_size > 1 when the time
taken by a single iteration is too small to be measured.
 
See Miller, p. 271 for the formula for the standard deviation of a
group. The same applies to a confidence interval, since its size is
directly proportional to the standard deviation (as shown above).
 
CPU usage is returned in the form of two 95% confidence intervals in
(center, range) form; they are respectively user and system CPU
usage in seconds. I.e.:
 
    ((user_center, user_delta), \
     (sys_center, sys_delta), \
     (real_center, real_delta))
 
With (1-alpha) probability, the user CPU time is in the range
user_center +/- user_delta. Likewise for system CPU time and real time.
run_program(program, args)
Runs a program, returning a tuple of user CPU, system CPU, and real
time.
 
"program" is the name of the program; the last path component is
sufficient if it is in ENV['path'].
 
"args" is a sequence of arguments. It include the program name.
 
Raises an exception if the program returns non-zero.
 
Data
             __file__ = './bench.pyc'
__name__ = 'bench'
inf = inf
large = 1.0000000000000001e+300
nan = nan