Commit c6daaccf authored by gabrieldemarmiesse's avatar gabrieldemarmiesse

Corrected a big mistake about speedup.

parent 1105d722
...@@ -270,7 +270,7 @@ It's possible to compare the speed now:: ...@@ -270,7 +270,7 @@ It's possible to compare the speed now::
>>> %timeit primes(500) >>> %timeit primes(500)
502 µs ± 2.22 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) 502 µs ± 2.22 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
The Cython version is 11 550 times faster than the Python version! What could explain this? The Cython version is 11 times faster than the Python version! What could explain this?
Multiple things: Multiple things:
* In this program, very little computation happen at each line. * In this program, very little computation happen at each line.
...@@ -281,10 +281,10 @@ Multiple things: ...@@ -281,10 +281,10 @@ Multiple things:
when using Python. Because everything in python is an object, and every object is when using Python. Because everything in python is an object, and every object is
implemented as a dictionary, this is not very cache friendly. implemented as a dictionary, this is not very cache friendly.
It's worth mentioning that you won't usually get speedups like this. Usually the speedups are between 2x to 1000x. It depends on how much you call
We very likeky touched a sweet spot with the CPU cache. Usually the speedups the Python interpreter. As always, remember to profile before adding types
are between 2x to 1000x. As always, remember to profile before adding types everywhere. Adding types makes your code less readable, so use them with
everywhere. moderation.
Language Details Language Details
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment