Open vsvasya opened 9 years ago
@vsvasya thanks for asking! I haven't checked, but I think it has to do with the chunked writing. The Python code is calling write
with a million bytes at a time. The cStringIO object's write
method likely uses memcpy
or a similar very tuned mechanism for writing the string.
Meanwhile, in fill_array.c
, it's writing a byte at a time, and also seems to be doing some computation in the loop. I don't know enough to figure out which part of that is slowing it down more, and this is all speculation! :-)
Oh, yes) I remember, what writing byte by byte is much slower then memsetting by dwords or even more if using SIMD.
Now, write_to_memory.py answer in this game is 2,000,000,000 bytes written in one second. But much simpler fill_array.c gives us just 376,000,000 bytes written in one second.
PS: Thank you! You create very cool thing! ))