print statements and profiling a function slowed performance

Chris Angelico rosuav at gmail.com
Thu Jun 26 23:14:57 EDT 2014


On Fri, Jun 27, 2014 at 12:55 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Thu, 26 Jun 2014 13:37:41 -0700, CM wrote:
>
>> On Thursday, June 26, 2014 3:27:48 PM UTC-4, Mark Lawrence wrote:
>>
>>> 3. use the logging module :)
>>
>> I've just never got around to it, but I guess I should.  Thanks for the
>> nudge.
>
> While using the logging module is recommended for logging, if you expect
> that logging will be faster than print, I expect you will be disappointed.

I would expect it to be faster than print in the case where it ends up
not printing, which means you can make one change to logging level and
very quickly eliminate all the output. I haven't measured, but I would
expect the overhead of the logging module itself to be small compared
to the cost of actual console output.

ChrisA



More information about the Python-list mailing list