[PYTHON MATRIX-SIG] RE: How time-consuming is array()?

janko hauser jhauser@ifm.uni-kiel.de
Tue, 29 Oct 1996 14:13:31 +0100


So, here are the tests

#! /home/caesar/u1/hauser/bin/python

from Numeric import *
import time
import nc


f_head=nc.open('th2.cdf')

t1 = time.time()

X=f_head.var('xp')
t2 = time.time()

X=array(X, Float32)
t3 = time.time()

print "elapsed walltime:", t2-t1, "vs.", t3-t2, "seconds"


I run it several times:

elapsed walltime: 0.000975966453552 vs. 0.0907679796219 seconds
elapsed walltime: 0.000975966453552 vs. 0.0952479839325 seconds
elapsed walltime: 0.0 vs. 0.109311938286 seconds
elapsed walltime: 0.0 vs. 0.092719912529 seconds
elapsed walltime: 0.0 vs. 0.0839359760284 seconds
elapsed walltime: 0.0 vs. 0.0917440652847 seconds
elapsed walltime: 0.0 vs. 0.0864640474319 seconds

Now the same script with 
	X=list(f_head.var('xp'))

elapsed walltime: 0.0409919023514 vs. 0.0361120700836 seconds
elapsed walltime: 0.0429439544678 vs. 0.0370880365372 seconds
elapsed walltime: 0.0380640029907 vs. 0.0331839323044 seconds
elapsed walltime: 0.0507519245148 vs. 0.0429440736771 seconds
elapsed walltime: 0.0419679880142 vs. 0.0390399694443 seconds

So it's not a problem in the NetCDF-package, only it
returns a sequence, isn't it? But array is time-consuming.

Are there any better way's to handle this.

(I think the best is to change the NetCDF-package to return an array
object.) 

Some more comments?

__Janko


=================
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================