What's the overhead of assertion or debug statements in Python?

Daniel Eloff danieleloff at hotmail.com
Sat Jul 17 07:23:52 CEST 2004

I've just started programming with Python, but I've heard it has a
feature rare among interpreted languages - Debug statements.]


According to the docs, assert() produces no code if optimization is


My question is, is the same true for


if __debug__:

            print "Reached this region of code", some_debug_func()




Is there any overhead associated with this at runtime? Any branching or
run time evaluation of the value of __debug__?


I'm trying to discover if I can litter my code with debug stuff, or if I
should go sparingly in performance critical code like some innermost


Also, how can I enable and disable optimization?




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20040716/96681e8e/attachment.html>

More information about the Python-list mailing list