PyWart: The problem with "print"

Ian Kelly ian.g.kelly at gmail.com
Mon Jun 3 13:12:05 EDT 2013


On Sun, Jun 2, 2013 at 6:16 PM, Jason Swails <jason.swails at gmail.com> wrote:
> I'm actually with RR in terms of eliminating the overhead involved with
> 'dead' function calls, since there are instances when optimizing in Python
> is desirable.  I actually recently adjusted one of my own scripts to
> eliminate branching and improve data layout to achieve a 1000-fold
> improvement in efficiency (~45 minutes to 0.42 s. for one example) --- all
> in pure Python.  The first approach was unacceptable, the second is fine.
> For comparison, if I add a 'deactivated' debugprint call into the inner loop
> (executed 243K times in this particular test), then the time of the
> double-loop step that I optimized takes 0.73 seconds (nearly doubling the
> duration of the whole step).

It seems to me that your problem here wasn't that the time needed for
the deactivated debugprint was too great. Your problem was that a
debugprint that executes 243K times in 0.73 seconds is going to
generate far too much output to be useful, and it had no business
being there in the first place.  *Reasonably* placed debugprints are
generally not going to be a significant time-sink for the application
when disabled.

> The easiest way to eliminate these 'dead' calls is to simply comment-out the
> print call, but I would be quite upset if the interpreter tried to outsmart
> me and do it automagically as RR seems to be suggesting.

Indeed, the print function is for general output, not specifically for
debugging.  If you have the global print deactivation that RR is
suggesting, then what you have is no longer a print function, but a
misnamed debug function.



More information about the Python-list mailing list