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

MRAB python at mrabarnett.plus.com
Tue Jun 5 14:40:10 EDT 2018


On 2018-06-05 18:25, Kyle Lahnakoski wrote:
> 
> 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.
> 
You'd get the same result with:

     if <control_flag>: log_function( <msg_expr> )

> *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> )
>>
>> Barry
>>
>> This idea requires the same sort of machinery in python that I was 
>> hoping for to implement the short circuit logging.
> 


More information about the Python-ideas mailing list