Python kernprof line profiler wrong results

609 views Asked by At

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?

1

There are 1 answers

0
EmeryBerger On

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 (i.e., adding @profile decorators is not required). Full disclosure: I am one of the primary authors of Scalene.