[Numpy-discussion] fromstring, tostring slow?
Tue Feb 13 15:38:47 CST 2007
Mark Janikas wrote:
> I am finding that directly packing numpy arrays into binary using the
> tostring and fromstring methods
For starters, use fromfile and tofile, to save the overhead of creating
an entire extra string.
fromfile is a function (as it is an alternate constructor for arrays):
ndarray.tofile() is an array method.
Enclosed is your test, including a test for tofile(), I needed to make
the arrays much larger, and use time.time() rather than time.clock() to
get enough time resolution to see anything, though if you really want to
be accurate, you need to use the timeit module.
Using lists 0.457561016083
Using tostring 0.00922703742981
Using tofile 0.00431108474731
Another note: where is the data coming from -- there may be ways to
optimize this whole process if we saw that.
Christopher Barker, Ph.D.
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
More information about the Numpy-discussion