简体   繁体   中英

Python kernprof line profiler wrong results

I have two functions which i profile. If i run kernprof, it says that my first function runs in 75 seconds but the second which is python-cythonized in 15.

I already tried to use the time module in python and measure it by myself i see that it's more like 12 seconds for the first function and 9 for the second.

Why is that so?

We examined a bunch of profilers and found that for the benchmark we used for testing (from the Pyperformance suite), using kernprof causes roughly a 7x slowdown when executing pure Python code. This is remarkably close to your observed execution time dilation (6.25x), so I believe this is almost certainly the cause.

If you want to use a profiler that has less overhead (nearly none) and is thus more accurate, there are a handful of options. I personally recommend Scalene , a profiler that simultaneously profiles CPU, GPU, and memory, all with very low overhead and with no need to modify your code (ie, adding @profile decorators is not required). Full disclosure: I am one of the primary authors of Scalene.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM