[Python] Large performance hit with Python logging module

Discussão em 'Python' iniciado por Stack, Março 25, 2025.

  1. Stack

    Stack Membro Participativo

    I typically use Python's inbuilt logging module to better debug my code during development. My typical codes are a bit performance sensitive. My assumption was that once I have completed debugging the code, I can simply set the logging level to WARNING and compiler would remove all the logger commands.

    I decided to profile the code to be sure, and viola, when I commented out all the logging calls - my code performance was 20x better compared to the code that had logging turned off by setting higher level. Which means, when you increase the logging level, compiler still leaves the logging with a branch, and the CPU performance poorly due to all the branches!

    Is this observation correct, or am I missing something completely?

    Continue reading...

Compartilhe esta Página