Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #61268

Re: Does Python optimize low-power functions?

Date 2013-12-07 19:00 -0700
From Michael Torrie <torriem@gmail.com>
Subject Re: Does Python optimize low-power functions?
References <5ea86e1b-f5b5-49d1-acfb-22ee4d9a1f16@googlegroups.com> <64aa230f94f04c938101f928ac1a0276@DM2PR06MB542.namprd06.prod.outlook.com>
Newsgroups comp.lang.python
Message-ID <mailman.3716.1386468041.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 12/06/2013 12:32 PM, Nick Cash wrote:
> Nope:
> 
> Python 3.3.0 (default, Sep 25 2013, 19:28:08) 
> [GCC 4.7.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import dis
>>>> dis.dis(lambda x: x*x)
>   1           0 LOAD_FAST                0 (x) 
>               3 LOAD_FAST                0 (x) 
>               6 BINARY_MULTIPLY      
>               7 RETURN_VALUE         
>>>> dis.dis(lambda x: x**2)
>   1           0 LOAD_FAST                0 (x) 
>               3 LOAD_CONST               1 (2) 
>               6 BINARY_POWER         
>               7 RETURN_VALUE         
> 
> 
> The reasons why have already been answered, I just wanted to point
> out that Python makes it extremely easy to check these sorts of
> things for yourself.

But this is just the interpreter bytecode that dis is showing.  It's not
showing the underlying implementation of binary_power, for example.
That could be defined in C code with any number of optimizations, and
indeed it appears that some are being done.  dis is great for showing
how python code breaks down, but it can't tell you much about the code
that underlies the byte codes themselves.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Does Python optimize low-power functions? John Ladasky <john_ladasky@sbcglobal.net> - 2013-12-06 10:16 -0800
  Re: Does Python optimize low-power functions? Neil Cerutti <neilc@norwich.edu> - 2013-12-06 19:01 +0000
  Re: Does Python optimize low-power functions? Robert Kern <robert.kern@gmail.com> - 2013-12-06 19:12 +0000
  RE: Does Python optimize low-power functions? Nick Cash <nick.cash@npcinternational.com> - 2013-12-06 19:32 +0000
    Re: Does Python optimize low-power functions? John Ladasky <john_ladasky@sbcglobal.net> - 2013-12-06 11:43 -0800
  Re: Does Python optimize low-power functions? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-12-06 20:57 +0000
  Re: Does Python optimize low-power functions? Michael Torrie <torriem@gmail.com> - 2013-12-07 19:00 -0700

csiph-web