Peter Otten wrote: > HYRY wrote: > >> I want to join two mono wave file to a stereo wave file by only using >> the default python module. >> Here is my program, but it is much slower than the C version, so how >> can I increase the speed? >> I think the problem is at line #1, #2, #3. > >> oarray = array.array("h", [0]*(len(larray)+len(rarray))) #1 > > ITEMSIZE = 2 > size = ITEMSIZE*(len(larray) + len(rarray)) > oarray = array.array("h") > oarray.fromstring("\0" * size) > > may be a bit faster.
Confirmed: $ python2.5 -m timeit -s'from array import array; N = 10**6' 'a = array("h"); a.fromstring("\0"*(2*N))' 100 loops, best of 3: 9.68 msec per loop $ python2.5 -m timeit -s'from array import array; N = 10**6' 'a = array("h", [0]*N);' 10 loops, best of 3: 199 msec per loop Peter -- http://mail.python.org/mailman/listinfo/python-list