When visual inspection fails, how do you determine where the slowest points in your code are? Where are the bottlenecks that are ruining your runtime?
+9
A:
Profile your code.
The data obtained is irrefutable in determining the performance bottlenecks.
and the following allows you to visualize the profile data
Bunch of performance tips
Hidden performance bottleneck: Find shlemiel the painter inside your code
Joel Spolsky blogged on "Shlemiel the painter's algorithm" which succinctly describes the problem of scale in solutions.
pyfunc
2010-10-18 01:40:05
Profiling isn't irrefutable, because profilers aren't perfect--but it's a very important tool. Granted, profilers are probably in general more accurate with Python than low-level languages, simply because high-level languages are so much slower that there's a lot more wiggle room for a profiler's overhead to not significantly alter the results.
Glenn Maynard
2010-10-18 01:51:56
@Glenn Maynard : Agreed! I guess the language of my reply is a bit more enthusiastic.
pyfunc
2010-10-18 01:54:36
Awesome response! Also, really interesting link on the python performance tips. Thanks!
coffee
2010-10-18 01:57:41
A:
I'll add to pyfunc's response.
You can profile python with some of the profilers available like cProfile
.
Links about Python profiling: http://docs.python.org/library/profile.html
birryree
2010-10-18 01:43:23