Benchmarking module for Python

Paul Moore paul.moore at uk.origin-it.com
Wed Jan 31 07:08:11 EST 2001


I'm looking for a method of benchmarking snippets of Python code, a
bit like Perl's Benchmark module. I have looked at the profile module,
but it doesn't seem to do quite what I want.

What I'm after, given a line of code, is something that will let me
run that line a specified number of times, say 1000, and see the
average time that the line took.

I can do something like that with profile, by wrapping my code in a
function, and profiling 'for i in xrange(1000): fn()', and then
extracting the time spent per call in fn(). But it's a bit of a long
way round to get what I want.

Ideally, I'd like to be able to reuse the timing code from profile,
but if not, then an independent benchmark module would be OK. All I
found on Parnassus was PyBench, which tests a standard set of tasks.

Is there any such thing, or should I start coding?

Paul.

PS Yes, I know that benchmarks are meaningless....




More information about the Python-list mailing list