[Python-ideas] Runtime assertion with no overhead when not active

Eloi Gaudry Eloi.Gaudry at fft.be
Wed Jun 6 04:34:13 EDT 2018

The check is made against a boolean value in the C extension, I don't think that it offers a significant speed-up against the pure python code.

but it offers a simpler (reduced, global) assertion syntax though.

From: Python-ideas <python-ideas-bounces+eloi.gaudry=fft.be at python.org> on behalf of Kyle Lahnakoski <klahnakoski at mozilla.com>
Sent: Tuesday, June 5, 2018 7:25:45 PM
To: python-ideas at python.org
Subject: Re: [Python-ideas] Runtime assertion with no overhead when not active

I currently use the form

    <control_flag> and log_function( <msg_expr> )

where <control_flag> is some module variable, usually "DEBUG".  I do this because it is one line, and it ensures the log_function parameters are not evaluated.

*IF* runtime assertions had a switch so they have no overhead when not active, how much faster can it get?  How expensive is the <control_flag> check?

On 2018-05-10 03:55, Barry Scott wrote:

My logging example would be

log( control_flag, msg_expr )

expanding to:

if <control_flag>:
log_function( <msg_expr> )


This idea requires the same sort of machinery in python that I was hoping for to implement the short circuit logging.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180606/2d3c49f2/attachment.html>

More information about the Python-ideas mailing list