Python Forum
CPython ruuntime codes - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: CPython ruuntime codes (/thread-32508.html)



CPython ruuntime codes - Skaperen - Feb-14-2021

is there a document that describes CPython's runtime codes? this would be the codes the compiler produces for the runtime interpreter to interpret. i am curious how easy it might be go a step further a generate C or machine codes to increase runtime execution performance in certain cases.


RE: CPython ruuntime codes - snippsat - Feb-14-2021

(Feb-14-2021, 01:32 AM)Skaperen Wrote: i am curious how easy it might be go a step further a generate C or machine codes to increase runtime execution performance in certain cases.
It's not easy PyPy has been working on this for 14 years.
PyPy generate C code as just one step to the Python code faster.
David Beazley explain this here

PyPy easy to use just run pypy3 instead of Python.
Usually is 1-2 version behind Python,so PyPy is on version 3.7 now.
# loop_test.py
import time

start_time = time.time()
total = 0
for i in range(1, 10000):
    for j in range(1, 10000):
        total += i + j

print(f"The result is {total}")
end_time = time.time()
print(f"It took {end_time-start_time:.2f} seconds to compute")
Output:
# Using Python 3.9.1 G:\pypy3.7 λ python loop_test.py The result is 999800010000 It took 16.97 seconds to compute # Using PyPy 3.7 G:\pypy3.7 λ pypy3 loop_test.py The result is 999800010000 It took 2.72 seconds to compute
Linux take down with pyenv and use.
# Using Python 
tom@tom-VirtualBox:~$ python -V
Python 3.9.1
tom@tom-VirtualBox:~$ python loop_test.py 
The result is 999800010000
It took 23.34 seconds to compute

# Take down PyPy 
tom@tom-VirtualBox:~$ pyenv install pypy3.7-7.3.3
continue with installation? (y/N) y
Downloading pypy3.7-v7.3.3-linux64.tar.bz2...
-> https://downloads.python.org/pypy/pypy3.7-v7.3.3-linux64.tar.bz2
Installing pypy3.7-v7.3.3-linux64...

# Set system wide
tom@tom-VirtualBox:~$ pyenv global pypy3.7-7.3.3
tom@tom-VirtualBox:~$ pypy3 -V
Python 3.7.9 (7e6e2bb30ac5, Nov 18 2020, 10:55:52)
[PyPy 7.3.3-beta0 with GCC 7.3.1 20180303 (Red Hat 7.3.1-5)]
# Run
tom@tom-VirtualBox:~$ pypy3 loop_test.py 
The result is 999800010000
It took 1.31 seconds to compute

There is lot going on in this field as eg Cython, Numba.
Python is big in Data Science where now GPU is prefeed over CPU to speed thing up.
Data Science on GPU


RE: CPython ruuntime codes - Skaperen - Feb-14-2021

i worked on a lot of dynamic typing in C long ago and that had a lot of issues in how to code it. C code was not easy and that may be why Pike still looked so static with require typing statements ("mixed" type was an add-on that still does not solve all the issues). one big reason i got into Python was because these issues were not present. i've been thinking more about this as an assembly language issue and started to get the idea this could really be made to work there if i can figure it out in C.

i was hoping Dave would have touched on dictionaries in that video. but a mixed list was good enough. that's really not so hard to handle in C (BTDTLA) i just keep thinking that Python can be the ultimate system language and it would be really cool with machine hardware designed around that (my thought is then an emulation of it).