![](https://secure.gravatar.com/avatar/af6c39d6943bd4b0e1fde23161e7bb8c.jpg?s=120&d=mm&r=g)
On Tue, Feb 13, 2007 at 11:42:35AM -0800, Mark Janikas wrote:
I am finding that directly packing numpy arrays into binary using the tostring and fromstring methods do not provide a speed improvement over writing the same arrays to ascii files. Obviously, the size of the resulting files is far smaller, but I was hoping to get an improvement in the speed of writing. I got that speed improvement using the struct module directly, or by using generic python arrays. Let me further describe my methodological issue as it may directly relate to any solution you might have.
Hi Mark Can you post a benchmark code snippet to demonstrate your results? Here, using 1.0.2.dev3545, I see: In [26]: x = N.random.random(100) In [27]: timeit f = file('/tmp/blah.dat','w'); f.write(str(x)) 100 loops, best of 3: 1.77 ms per loop In [28]: timeit f = file('/tmp/blah','w'); x.tofile(f) 10000 loops, best of 3: 100 µs per loop (I see the same results for heterogeneous arrays) Cheers Stéfan