python profiling, hotspot and strange execution time

cournape at cournape at
Tue Sep 6 10:25:01 CEST 2005

Hi there,

   I have some scientific application written in python. There is a
good deal of list processing, but also some "simple" computation such
as basic linear algebra involved. I would like to speed things up
implementing some of the functions in C. So I need profiling.

   I first tried to use the default python profiler, but profiling my
application multiplies the execution time by a factor between 10 and
100 ! So I decided to give a try to hotspot. I just followed the
example of the python library reference, but I have some strange
results concerning cpu time. My profiling script is something like the

def run_foo():
    print time.clock()


    print time.clock()

prof = hotshot.Profile("")
benchtime= prof.runcall(run_foo)
stats = hotshot.stats.load("")
stats.sort_stats('time', 'calls')

The goal is to profile the function function_to_profile(). Running this
script gives me a CPU executime time of around 2 seconds, whereas the
difference between the two clock calls is around 10 seconds ! And I
don't run any other cpu consuming tasks at the same time, so this
cannot come from other running processes. Is there something perticular
about hotspot timing I should know ? I am not sure how I can get more
accurate results with hotspot.

I would appreciate any help, 


More information about the Python-list mailing list