Which coding style is better? public API or private method inside class definition

Carey Tilden carey.tilden at gmail.com
Thu Jan 6 16:19:47 EST 2011


On Wed, Jan 5, 2011 at 9:15 AM, Peter Otten <__peter__ at web.de> wrote:

> Jacek Krysztofik wrote:
>
> > Sorry for OT, but this is actually a question of mine
> >>                 if numbers % 2 == 0:
> > wouldn't the following be faster?
> >>                 if numbers & 1 == 0:
>
> You can answer that and similar questions yourself with the timeit module:
>
> $ python -m timeit -s'm, n = 1234, 1235' 'm % 2 == 0; n % 2 == 0'
> 1000000 loops, best of 3: 0.377 usec per loop
>
> $ python -m timeit -s'm, n = 1234, 1235' 'm & 1 == 0; n & 1 == 0'
> 1000000 loops, best of 3: 0.298 usec per loop
>
> So yes, a binary and seems to be faster.
>

I would be curious to hear of a Python application where such a small speed
difference mattered even a little bit.  Looks to me like a pretty
meaningless difference.

Carey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110106/3a069875/attachment-0001.html>


More information about the Python-list mailing list