This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Docbench is a framework based on doctest to benchmark Python code. If you already are familiar with doctest, you should be able to use docbench in minutes. And if you find that doctest is convenient – or Pythonic – hopefully you will feel the same about docbench !


We will walk you through the use of docbench with a simple use case: a module that computes prime numbers.

Create a primes.py file and define the primes function:

def primes(n):
    p = []
    for i in range(2, n+1):
        for j in range(2, i):
            if (i % j == 0):
                break
        else:
            p.append(i)
    return p

The function returns an ordered list of primes numbers up to the number n. Its implementation is simple but the execution takes a lot of time when n grows. The following sieve function should return the same result, but performs less computations and therefore should be faster.

def sieve(n):
    p = []
    for i in range(2, n+1):
        prime = True
        for j in p:
            if j * j > i:
                break
            if (i % j == 0):
                prime = False
                break
        if prime:
            p.append(i)
    return p

Doctest – Does it Work ?

If you already know doctest, you may skip this section.

Testing this module with doctest is pretty straightforward: create a test.py file with a function test_primes with no implementation but a doctest for the primes function:

def test_primes():
    """
    >>> from primes import primes
    >>> n = 50
    >>> primes(n)
    [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
    """

You are pretty confident that if test_primes doctest works as advertised in this doctest, the primes function behaves correctly. Therefore, you may now test sieve against primes:

def test_sieve():
    """
    >>> from primes import primes, sieve
    >>> n = 10000
    >>> primes(n) == sieve(n)
    True
    """

Finally, add the following boilerplate a the end of your file:

if __name__ == "__main__":
    import doctest
    doctest.testmod()

You are ready to execute this test suite with:

$ python test.py

No error displayed ? The primes module has successfully passed all tests !

Docbench – Is is Fast ?

Create a new file name benchmark.py. Add functions that act as docbench holders for the function primes and sieve. We rely on the convention that only the time spent in the last statement of any docbench will be measured, the previous ones are considered setup code.

def benchmark_primes():
    """
    >>> from primes import primes
    >>> n = 10000
    >>> primes(n)
    """

def benchmark_sieve():
    """
    >>> from primes import sieve
    >>> n = 10000
    >>> sieve(n)
    """

Add the following boilerplate at the end of your file:

if __name__ == "__main__":
    import docbench
    docbench.benchmod()

Run your benchmark with:

$ python benchmark.py

You should end up with an output similar too:

Benchmark                  Time
-------------------------  ----------------
__main__.benchmark_primes  1.03
__main__.benchmark_sieve   0.00876

Indeed, sieve is quite faster than primes !

Release History

Release History

1.0.0-alpha.6

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.0-alpha.5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.0-alpha.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.0-alpha.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.0-alpha.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
docbench-1.0.0-alpha.6.tar.gz (37.4 kB) Copy SHA256 Checksum SHA256 Source Aug 7, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting