shared_numpy icon indicating copy to clipboard operation
shared_numpy copied to clipboard

Why this is so much faster ?

Open lamhoangtung opened this issue 4 years ago • 2 comments

Hi, thanks for the great works. I'm testing out this module with the timing_comparison.py script provided.

Since this was only made for Python 3.6 and 3.7, and made a clone of this for Python 3.8 with: from shared_numpy.shared_memory import SharedMemory but the result is soo much worse than your implementation:

shared_numpy (Python 3.7):

not shared
total time: 1.25028395652771
shared
total time: 0.008873939514160156

My shared_numpy clone using Python 3.8:

not shared
total time: 1.307685136795044
shared
total time: 0.238494873046875

That's 26 times slower for the same test conditions.

I'm wondering why ? Are there any magic sauce in your SharedMemory implementation vs python 3.8 SharedMemory ?

Also, can your SharedMemory works on Windows as well ?

Hope you can clear me out here. Thanks for checking by @dillonalaird!

lamhoangtung avatar May 12 '21 06:05 lamhoangtung

Python 3.8 is the first version of Python that implements SharedMemory, so you should be using the official SharedMemory class instead of the one built in this repo https://docs.python.org/3/library/multiprocessing.shared_memory.html

I would imagine it's just changing

from shared_numpy.shared_memory import SharedMemory

to

from multiprocessing.shared_memory import SharedMemory

conditioned on the Python version

dillonalaird avatar Aug 27 '21 16:08 dillonalaird

Yeah that's what I did and turn out it's much slower than yours @dillonalaird

lamhoangtung avatar Aug 28 '21 03:08 lamhoangtung