How to Write Fast Python Code

Veröffentlicht am: 26 Oktober 2022
auf dem Kanal: Red Black Tech
537
27

This short highlights a quirk of Python that enables a Python program to run at much faster speeds than typical user-space Python code.

There are multiple implementations of the Python interpreter in different programming languages, including but not limited to C and Java (In case you're unfamiliar, languages are either written in other programming languages or in assembly language - a topic for another day).

When installing C-Python on your computer, you're actually installing a C program on your computer that eventually is compiled into a specific path in your computer like /usr/bin/python3. It is at compilation time that builtin functions, like list and map, are implemented in C-Python, meaning those functions are written in C, which makes them much faster.

This video benchmarks two functions that append to a list in Python: one using a Python for loop, and the other using builtin functions list and map. The latter implementation ends up being 40% faster than the prior.

Note: although this video shows a method of increasing your Python code's speed, the technique is not an excuse to avoid asymptotic analysis and to figure out asymptotically better methods of writing functions.


Auf dieser Seite können Sie das Online-Video How to Write Fast Python Code mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Red Black Tech 26 Oktober 2022 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 537 Mal angesehen und es wurde von 27 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!