I'm trying to profile some very simple code (using both cProfile and pyinstrument). The code is:
sum(1 for e in range(1533939))
When running the code without the profiler active, it is very quick (~85ms). However when attempting to run the same code in a profiler, it suddenly takes almost 13 seconds.
I'm doing this (in a Jupyter notebook):
%%prun
sum(1 for e in range(1533939))
I figured the problem is the overhead caused by the numerous calls to "next" inside the generator expression, however, running the same experiment on my host machine (not inside the container) is not showing a slowdown when profiling.
Any idea why the profiler might be slowing this code down so much?
For the record, I'm using Jupyter's container "jupyter/scipy-notebook" as the base container.
Thanks!
python -c 'import cProfile; cProfile.run("sum(1 for e in range(1533939))")'
directly is dramatically different between the two? – Teeth