Skip to main content

a small utility for benchmarking

Project description

Benchmarker is a small utility to benchmark your code.

See CHANGES.txt for details of changes and enhancements.

Example (ex.py):

def fib(n):
    return n <= 2 and 1 or fib(n-1) + fib(n-2)
from benchmarker import Benchmarker
bm = Benchmarker(30)  # or Benchmarker(width=30, out=sys.stderr, header=True)
## Python 2.5 or later
with bm('fib(n) (n=33)'):  fib(33)
with bm('fib(n) (n=34)'):  fib(34)
with bm('fib(n) (n=35)'):  fib(35)
## Python 2.4
bm('fib(n) (n=33)').run(fib, 33)   # or .run(lambda: fib(33))
bm('fib(n) (n=34)').run(fib, 34)   # or .run(lambda: fib(34))
bm('fib(n) (n=35)').run(fib, 35)   # or .run(lambda: fib(35))
## print compared matrix
bm.print_compared_matrix(sort=False, transpose=False)
# or print(bm.compared_matrix())

Output:

$ python ex.py
                          utime     stime     total      real
fib(n) (n=33)             1.890     0.000     1.890     1.900
fib(n) (n=34)             3.030     0.010     3.040     3.058
fib(n) (n=35)             4.930     0.010     4.940     4.963
---------------------------------------------------------------
                           real      [01]     [02]     [03]
[01] fib(n) (n=33)       1.900s        -     60.9%   161.2%
[02] fib(n) (n=34)       3.058s    -37.9%       -     62.3%
[03] fib(n) (n=35)       4.963s    -61.7%   -38.4%       -

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for Benchmarker, version 1.1.0
Filename, size File type Python version Upload date Hashes
Filename, size Benchmarker-1.1.0-py2.4.egg (7.4 kB) File type Egg Python version 2.4 Upload date Hashes View
Filename, size Benchmarker-1.1.0-py2.5.egg (7.4 kB) File type Egg Python version 2.5 Upload date Hashes View
Filename, size Benchmarker-1.1.0-py2.6.egg (7.4 kB) File type Egg Python version 2.6 Upload date Hashes View
Filename, size Benchmarker-1.1.0-py2.7.egg (7.3 kB) File type Egg Python version 2.7 Upload date Hashes View
Filename, size Benchmarker-1.1.0.tar.gz (10.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page