Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Does loading PDB slow down execution?

288 views
Skip to first unread message

Unixnut

unread,
Oct 3, 2021, 6:00:20 PM10/3/21
to
Hi all,

If I run a python3 program with "import pdb" in the code, would it
execute slower than without loading the debugger?

The program I am running is computationally expensive and mathematically
orientated. It is expected to run for a few months (I am a few days in).
I found out today that I forgot to comment out the "import pdb" while
debugging, and now I am wondering if there would be a performance
benefit worth restarting the execution with pdb unloaded.

I have tried testing this with a simple sum executable, but I don't see
a clear difference with short execution times (<5 mins). Before I
investigate further, I thought I would ask and see if anyone knows the
answer already.

Many thanks!

Dieter Maurer

unread,
Oct 6, 2021, 1:50:05 PM10/6/21
to
Unixnut wrote at 2021-10-3 22:03 +0100:
>If I run a python3 program with "import pdb" in the code, would it
>execute slower than without loading the debugger?

Importing `pdb` does not slow down the application significantly
(it just adds the import time but does not otherwise affect the
application).

Only when you execute code under debugger control, the
execution is significantly slowed down (because the debugger
gets informed (via callbacks) about important "event"s (entering
a line, function call, function return, exception) during
the execution).

Unixnut

unread,
Oct 27, 2021, 2:00:18 PM10/27/21
to
Excellent, many thanks for confirming. I can leave the execution running
then.

Benjamin Schollnick

unread,
Oct 27, 2021, 3:47:32 PM10/27/21
to
But it’s pointless to import pdb, if you aren’t going to use it.

I would suggest that a best practice would be to only import pdb, if and when you were going to be performing the debugging.
(So maybe set a boolean constant, that would cause the import, and debugging code to be executed.

Peter J. Holzer

unread,
Oct 27, 2021, 3:52:31 PM10/27/21
to
On 2021-10-27 15:47:08 -0400, Benjamin Schollnick wrote:
> > On Oct 27, 2021, at 1:01 PM, Unixnut <uni...@witheredfire.com> wrote:
[...]
> > Excellent, many thanks for confirming. I can leave the execution running then.
>
> But it’s pointless to import pdb, if you aren’t going to use it.

Please read the first mail in this thread.

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | h...@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
signature.asc
0 new messages