Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CPython ruuntime codes
#1
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
(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
Reply
#3
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).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how hard would it be to integrate CPython in a web browser? Skaperen 1 1,172 Feb-19-2023, 02:15 PM
Last Post: snippsat
  efficiency of CPython expression comppilation Skaperen 1 1,300 Jan-09-2022, 06:03 AM
Last Post: casevh
  Guido van Rossum about starting contributing to CPython buran 0 2,328 Feb-18-2020, 04:44 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020