Speed Up Your Code With Cython

preview_player
Показать описание
Today we learn how to speed up Python code, using Cython.

◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚

🌐 Social Media & Contact 🌐

Рекомендации по теме
Комментарии
Автор

When using the time module to benchmark something use time.perf_counter() rather than time.time() as it provides more precision and isn't the time since the epoch!

Magmurrr
Автор

This is actually pretty useful
I wasn't aware that cython was a thing until now
Thanks for this!

holo
Автор

Here I was trying to attach Python to my C, when really I should try attaching C style to Python. 👍 Great vid. You've given me something to consider.

BobBeatski
Автор

If both functions are in the same source file, both will be compiled I assume? Have you tried putting the optimised function in a separate pyx file and only compiling that?

Finally you might be able to do number += 2 because prime numbers cannot be even anyway.

barendscholtus
Автор

This is an example of Cython working better, but how about a comprehensive tutorial on how to use it? Does it work when you're using machine learning libraries?

isaacbaum
Автор

It's not only about static typing, but also probably about predefined vs dynamic sized array. Dynamical array size definitely comes at a cost.

gaelc
Автор

There is a way to make your prime detecting more efficient. The only even prime number is 2 so there is no need to test the remaining even numbers. It would be more efficient to insert 2 in the list at the beginning of the program, then start testing at 3 and increment the number to be tested by 2 each time instead of by 1 as you did. This would double the speed of the program since there would be only half as many numbers to be tested. Another thing to consider is that when testing a number for primality it is not necessary to check if any prime less than the number divides it. It is only necessary to check if any prime less than its square root divides it. But I'm not sure how much this would speed up the program (if at all) due to the overhead of calculating the square root of each number to be tested (unless you used a relatively simple formula to approximate the square root instead of calculating a precise value).

brucea
Автор

Thanks again for a great video. I like that you use Windows as well.
It was cool to see the speed of : flexibility of Python vs rigidness of cython

hyakushiki
Автор

Great video! I would love to watch more of those Cython vs Python

rushas
Автор

When I do "import main" in VSCode, it says "import main could not be resolved"

JackyVSO
Автор

Why [p for p in primes[:found]] instead of just primes[:found] you're literally iterating through each number of a list, putting it in another list and returning the new list. (?!?!?!?!)

totalpieceofhit
Автор

me: wants to know about cython because python is soo slow
NeuralNine: I have read your mind, here you go.
Thanks!

ajiteshkumar
Автор

I learnt many things
But I had a request to plz make a short playlist for these types of all modules which can useable for python

Plz teaches us cython syntax and all stuff in detail as well as pandas and numpy

I want to learn those thing

Plz sir

abhinavchoudhary
Автор

Will there be a follow up with C-Extension and a comparison with cython?

victordvickie
Автор

can someone please explain why we used when defining the "primes"? Why not use something like "primes[amount]"?

EshaanIITM
Автор

Yeah, you can also work with numpy arrays instead of regular lists and it will work much faster without all the need of that c complexity sintax, but great video anyway, I'll search about this way of programming

hectorminator
Автор

Woah! What's this for-else code? Can you you use else with for loops? I'll have to look that up. Didn't know about that. Learn something every day.

roccov
Автор

First I Love C# and Python. Now I Love Cython too

cyanuranus
Автор

make a tutorial on compiling .pyx to .c to .exe. The executable should run without any dependencies

martyrdm
Автор

Import turtle 🐢 small tutorial video bro 👍👍👍👍

s.aravindh