On Mon, Jan 08, 2007 at 02:38:50PM +1100, Mark Greenaway wrote:
> Erik de Castro Lopo wrote:
> >Does anyone have any experience profiling Python code? I've done
> >a bit of googling but haven't really found anything.
> >  
> Once upon a time, when I was working at CommSecure, we used to do this a 
> lot. This part of the library reference should get you started 
> http://docs.python.org/lib/profile.html.
> What exactly is the problem? Just want to know where your code spends its 
> time?

Note that in Python 2.5 cProfile is probably a better choice (for earlier
versions, google for and install lsprof).

On a related note, a useful tool for ad hoc microbenchmarks is timeit.  Invoke
as:

    python -m timeit -s "setup" -s "more_setup" "statement to benchmark"

e.g.

$ python -m timeit "x = 34" "x + x"
10000000 loops, best of 3: 0.192 usec per loop
$ python -m timeit "x = 34" "x * 2"
1000000 loops, best of 3: 0.224 usec per loop
$ python -m timeit "x = 34" "x << 1"
1000000 loops, best of 3: 0.219 usec per loop

-Andrew.

_______________________________________________
coders mailing list
[email protected]
http://lists.slug.org.au/listinfo/coders

Reply via email to