Building CPython
BartC
bc at freeuk.com
Thu May 14 17:55:42 EDT 2015
On 14/05/2015 17:29, Marko Rauhamaa wrote:
> BartC <bc at freeuk.com>:
>
>> That's a shame because I wanted to tinker with the main dispatcher
>> loop to try and find out what exactly is making it slow. Nothing that
>> seems obvious at first sight.
>
> My guess is the main culprit is attribute lookup in two ways:
>
> * Each object attribute reference involves a dictionary lookup.
>
> * Each method call involves *two* dictionary lookups plus an object
> creation.
>
> Tell us what you find out.
I'm just starting but I can tell you that it isn't because debug mode
(Py_DEBUG defined) was left on by mistake!
What is interesting however is that on the very simple test I'm doing (a
while loop incrementing a variable up to 100 million), the timings under
Windows are:
Python 2.5 9.2 seconds
Python 3.1 13.1
Python 3.4.3 17.0
Python 3.4.3 14.3 (under Ubuntu on same machine, using the version
I built today)
That's quite a big range!
PyPy does it in 0.7 seconds. The same program within my own *simple*
bytecode interpreter (not for Python) has a fastest time of 1.5 seconds
but makes use of ASM. A version 100% in (gcc) C can manage 2 seconds.
So far I haven't find anything that explains the discrepancy (the
languages are different, mine is simpler, but the Python code isn't
doing anything that complicated, only LOAD_FASTs and such, and LOAD_FAST
is apparently just an array access.
But the nearly 2:1 difference between new and old Python versions is
also intriguing.
def whiletest():
i=0
while i<=100000000:
i=i+1
whiletest()
--
Bartc
More information about the Python-list
mailing list