Building CPython
BartC
bc at freeuk.com
Thu May 14 20:50:35 EDT 2015
On 14/05/2015 22:55, BartC wrote:
> def whiletest():
> i=0
> while i<=100000000:
> i=i+1
>
> whiletest()
>
> 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.
(Actually my ASM-aided code took 0.5 seconds (some crucial section had
been commented out). Faster than PyPy and just using simple brute-force
methods.)
> 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.
It turns out the LOAD_FASTs were the simple byte-codes!
I'm just starting to find out just how much of a big complicated mess
this project really is. I wouldn't be surprised if there aren't many
people who actually understand it all, and that would explain why no-one
seems to have had much luck in getting the speed up (if anything, it's
getting slower).
I still have no idea yet exactly what an object comprises. I know that
even an innocuous-looking LOAD_CONST actually loads a tuple from a table
(complete with flag testing and bounds checks, although taking those out
made no discernible difference).
It appears to be those "<=" and "+" operations in the code above where
much of the time is spent. When I trace out the execution paths a bit
more, I'll have a better picture of how many lines of C code are
involved in each iteration.
--
Bartc
More information about the Python-list
mailing list