Simple Python code that runs for an oddly long time is incorrectly reported by Hotshot

I am trying to optimize some code with a hotshot, which I expected to be excellent, because it is a high-performance profiler and that’s all. But for some reason, I get wildly inaccurate results from him. In my last profiling run, hotshot reported a cumulative time for the top-level function, which I called 7.946 seconds. But even without taking into account time, I can say that it takes much more time. The timelines for running time, just using time.time (), gives me a runtime of 42.465 seconds. I assume this is because hotshot does not take into account system I / O time or something else, and my program performs batch processing of a large number of binary files?

However, using a few more time.time () blocks, I narrowed most of the extra time (which hotshot doesn't notice) to a lower-level processing function that doesn't do any I / O. hotshot reported the total and cumulative time that this function took as 4.414 and 6.185 seconds, respectively. However, using the time.time () expressions again, I found that its total time was more than 30 seconds. The total time spent in one relatively simple block of code was 7.32 seconds, which was spent on the whole function longer than hotshot said. The block is as follows:

format = element[1]
if isinstance(format, tuple):
    format, operator, operand = format
else:
    operator, operand = (None, None)

. 9 , , , , . . hotshot , ( )?

, , - .

+5
2

, , ? . , , , . .

gprof, , , , , " " , .

0

Python 2.5+, cProfile. , hotshot .

+2

All Articles