[Python-Dev] (#19562) Asserts in Python stdlib code (datetime.py)
solipsis at pitrou.net
Sun Nov 17 11:35:21 CET 2013
On Sun, 17 Nov 2013 21:27:24 +1100
Steven D'Aprano <steve at pearwood.info> wrote:
> On Sun, Nov 17, 2013 at 11:00:50AM +0100, Antoine Pitrou wrote:
> > On Sun, 17 Nov 2013 18:04:43 +1100
> > Steven D'Aprano <steve at pearwood.info> wrote:
> > > On Sat, Nov 16, 2013 at 04:46:00PM +0100, Antoine Pitrou wrote:
> > >
> > > > I agree that conflating the two doesn't help the discussion.
> > > > While removing docstrings may be beneficial on memory-constrained
> > > > devices, I can't remember a single situation where I've wanted to
> > > > remove asserts on a production system.
> > > >
> > > > (I also tend to write less and less asserts in production code, since
> > > > all of them tend to go in unit tests instead, with the help of e.g.
> > > > mock objects)
> > >
> > > I'm the opposite. I like using asserts in my code, and while I don't
> > > *typically* run it with -O, I do think it is valuable to have to
> > > opportunity to remove asserts. I've certainly written code where -O has
> > > given a major micro-optimization of individual functions (anything up to
> > > 50% speedup). I've never measured if that lead to a significant
> > > whole-application speedup, but I assume that was some benefit. (I know,
> > > premature optimization and all that...)
> > So you assumed there was some benefit, but you never used it anyway?
> I had a demonstrable non-trivial speedup when timing individual
> functions. At the time I considered that "good enough". If you want to
> call that "premature optimization", I can't entirely disagree, but can
> you honestly say you've never done the same?
You didn't answer my question: did you actually use -OO in production,
or not? Saying that -OO could have helped you optimize something you
didn't care about isn't a very strong argument for -OO :)
What I would like to know is if people *knowingly* add costly asserts
to performance-critical code, with the intent of disabling them at
runtime using -OO.
(in Python, that is, I know people do that in C where the programming
culture and tools are different)
More information about the Python-Dev