[Twisted-web] [Twisted-Python] Speed of rendering?

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Fri Jan 4 14:58:13 EST 2013

On 06:30 pm, peter.westlake at pobox.com wrote:
>A while back I promised to write some benchmarks for
>twisted.web.template's flattening functions. Is something like this
>suitable? If so, I'll add lots more test cases. The output format could
>be improved, too - any preferences?

The output should be something that we can load into our codespeed 
instance.  The output of any of the existing benchmarks in lp:twisted- 
benchmarks should be a good example of that format (I don't even recall 
what it is right now - it may not even be a "format" so much as a shape 
of data to submit to an HTTP API).

The `timeit` module is probably not suitable to use to collect the data, 
as it makes some questionable choices with respect to measurement 
technique, and at the very least it's inconsistent with the rest of the 
benchmarks we have.

Selecting data to operate on is probably an important part of this 
benchmark (or collection of benchmarks).  It may not be possible to 
capture all of the interesting performance characteristics in a single 
dataset.  However, at least something that includes HTML tags is 
probably desirable, since that is the primary use-case.

There are some other Python templating systems with benchmarks.  One 
approach that might make sense is to try to build analogous benchmarks 
for twisted.web.template.  (Or perhaps a little thought will reveal that 
it's not possible to make comparisons between twisted.web.template and 
those systems, so there's no reason to follow their benchmarking lead.)

>from twisted.web.template import flatten
>from twisted.web.server import Request
>import twisted.web.http
>channel = twisted.web.http.HTTPChannel()
>request = Request(channel, False)
>def make(content):
>    def f():
>        d = flatten(request, content, lambda _: None)
>        assert d.called
>    return f
>def test(content):
>    return timeit.timeit(stmt=make(content), number=repeats)
>repeats = 1000
>deeplist = ['centre']
>for n in range(100):
>    deeplist = [deeplist]
>tests = {
>    'empty': '',
>    'string': 'hello',
>    'shortlist': ['hello'],
>    'longlist': [str(n) for n in range(100)],
>    'deeplist': deeplist,
>if __name__ == '__main__':
>    import timeit
>    from sys import argv
>    for name in argv[1:] or tests:
>        print name, test(tests[name])
>Twisted-web mailing list
>Twisted-web at twistedmatrix.com

More information about the Twisted-web mailing list