Achieving C-like performance in Python without Cython or other libraries?

preview_player
Показать описание

I'm covering another Python optimization question this time: "What is the easiest way to achieve C-like performance in Python without in-depth knowledge of Cython or other libraries?"

Got a question? Leave a comment with your Python or general software dev question on this video and I'll try to cover it question in one of the next "#PythonQ&A" videos.

* * *

FREE Python Coding Tutorials & News:
Рекомендации по теме
Комментарии
Автор

Never knew dr Strange does programming tutorials

Hephasto
Автор

wow dude you look like benedict cumberbatch

tisaname
Автор

Thank you so much. My program which does stuff that make it incompatible with cython now runs 32 times faster! Wow!

nodroGnotlrahC
Автор

Some potentially simpler options:

Use generators when possible over iterators.

Keep similar data packed as closely as possible.

Architect the program for performance - this one actually means planning ahead so that you have an architecture instead of a hacked up architecture look-alike. For example, in programs with huge numbers of entities like a game, adopting an architecture like ECS can make things go more smoothly. Hell, even if someone just takes the time to learn what OOP principles are and actually follow them (still not sure if I've ever seen a proper OOP program, Even just considering encapsulation)

kiraPhk
Автор

I study bioinformatics and have to process large strings of dna or proteins in my projects. Pypy is actually quite a bit slower for these tasks. It seems that most techniques that circumvent pythons slowness are centered around numerical computations, but I haven’t encountered any that actually make parsing strings faster

ChimeraGilbert
Автор

i think what would attract more viewers is a short demo on how you use what you're talking about. Some folks retain more through visual.

redhatfan
Автор

I would also add numba package to the list if you are heavily working with numpy. That will also provide just in time compiler for numpy functions

MehmetOnerYalcn
Автор

If the task is numerical, using Numba is also a great option. All it takes is one decorator. Also for anyone willing to invest a bit more time it can leverage Cuda GPUs too

atrumluminarium
Автор

If you have the time or make the time, would love to see you working on the Pi with that program. Thx! Matt

mattbrown
Автор

Thank you I am going to take a look at this.

ftapiavalentin
Автор

The differences in Cython and Python for achiving these results is minimal. Placing a cdef in place of def or declaring an int n a variable is ot much work for the performance you gain.

djsensacion
Автор

I love this brother. Thanks for your knowledge.

bobbydreamsforu
Автор

Using pre defined functions only is good way to catch c++

ahmetyusufklc
Автор

Plz make a video on comparison different python implementations like CPython, PYPY, Jython etc

faisaltasleemft
Автор

Thanks a lot really enjoy it. by the way how is the support in 2020? are numy, pandas, torch, tf, etc supported now?

amortalbeing
Автор

I'm not tying to be mean. I'm sure someone thinks this statement will be. Never the less I'll say it.

He has the perfect face and voice for podcast.

KidaleSmith
Автор

Can we code a Linux like os in Python? Is Python a general purpose language capable of that..??

bellpepper
Автор

Do You freelance or you have any other source of earning other than youtube and ur site

rahulvairagi
Автор

I am running this program on python3 interpreter, after I run with pypy interpreter but looks pypy is slower then normal interpreter. if some one can test this code I will be appretiated ( i am a beginner )

import time
start_time = time.time()


a = 1
b = 2
c = a + b
total = a + b + c

for i in range(0, 2000):
a = b
b = c
c = a + b
print(c)

calculation_time = time.time() - start_time
print(f"Calculation time is: {calculation_time}")

blabla-kkbl
Автор

pypy only supporting tkinter as gui framework, with very less modules support and application packaging modules not able to install like cx-freeze, pyinstaller, py2exe, etc, I'm on anaconda and it's highly impossible to shift to pypy, please make indepth tutorial on how these can be achived using pypy

JackSparrow-vhzz