[Python-ideas] Specifying constants for functions
Sven R. Kunze
srkunze at mail.de
Tue Oct 27 14:35:24 EDT 2015
I totally agree here.
On 27.10.2015 19:18, Guido van Rossum wrote:
> IIRC it's an old micro-optimization; this was a common idiom at Zope.
> But I think it's way overused -- people believe it works so they do it
> all the time, even for code that's not performance sensitive, just
> because it's become a habit. (Like "register" in C in the '80s.)
>
> On Tue, Oct 27, 2015 at 10:55 AM, Yury Selivanov
> <yselivanov.ml at gmail.com <mailto:yselivanov.ml at gmail.com>> wrote:
>
> Serhiy,
>
> On 2015-10-27 1:45 PM, Serhiy Storchaka wrote:
>
> There is known trick to optimize a function:
>
> def foo(x, y=0, len=len, pack=struct.pack, maxsize=1<<BPF):
> ...
>
> It has a side effect: change function's signature. Would be
> nice to have a way to set function's local variables at
> creation time without affecting a signature.
>
>
> I see this a lot in all kinds of code. In my experience it
> doesn't actually speed things up in a measurable way.
>
> Is the below code really much slower?
>
> def foo(x, y=0):
> pack=struct.pack
> maxsize=1<<BPF
> #CODE
>
> If the #CODE is a tight long-running loop - then no, because the
> loop will probably run much longer than an extra attribute lookup
> + one extra bit shift on each "foo()" call. And if there is no
> tight loop - then you won't probably notice those optimizations
> anyways.
>
> I think that adding a "const" statement deserves some discussion,
> but not from the standpoint of micro-optimizations.
>
> Thanks,
> Yury
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org <mailto:Python-ideas at python.org>
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
>
>
>
> --
> --Guido van Rossum (python.org/~guido <http://python.org/%7Eguido>)
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151027/5ce83c1d/attachment-0001.html>
More information about the Python-ideas
mailing list