print statements and profiling a function slowed performance

Ian Kelly ian.g.kelly at gmail.com
Fri Jun 27 17:35:38 EDT 2014


On Fri, Jun 27, 2014 at 10:05 AM, Skip Montanaro <skip at pobox.com> wrote:
> On Fri, Jun 27, 2014 at 10:55 AM, Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:
>> Expectations don't count, measure it :)
>
> It's no contest. I have measured it (ages ago). The logging module
> does so many things that it's impossible for it to ever be as fast as
> a simple print statement. Look at the code in LogRecord.__init__. Then
> note the doc string:
>
> ... LogRecord instances are created every time something is logged. ...

While I'm not disputing your measurement, doesn't the logging module
delegate the actual I/O to a separate thread?  That's got to count for
something, compared to a raw print that has to wait for the I/O to
finish.



More information about the Python-list mailing list