[Numpy-discussion] Speed performance on array constant set
Mark Heslep
mark at mitre.org
Thu Jan 19 19:22:05 CST 2006
Im doing some work with the OpenCv* project. Im using swig typemaps to
convert the Cv data structures to numarray which works well. Id like to
restrict Cv use to what its strengths: complicated vision processing
algorithms like optical flow. For the case of simple Cv data
manipulations, I'd rather use NumPy functions & methods but was
surprised at the performance comparison.
- A simple scalar constant fill with cvSet. 'im' here is a wrapped Cv
image data structure.
> python -m timeit -s "import opencv.cv as cv; im =
> cv.cvCreateImage(cv.cvSize(1000,1000), 8, 1)" "cv.cvSet( im,
> cv.cvRealScalar( 7 ) )"
> 100 loops, best of 3: 2.58 msec per loop
- If I try the equivalent with NumPy
> python -m timeit -s "import numarray as na; a = na.zeros((1000,1000)
> )" "a[:,:] = 7"
> 10 loops, best of 3: 45.1 msec per loop
A >10x hit. Am I using the preferred / optimal NumPy method here? I
scanned the earlier Scalar posts but thought that was boolean type
only issue.
Mark
*OpenCv is an computer vision library, open source, and is sponsored by
Intel. It includes many video capable functions for application to
motion analysis, tracking and the like.
More information about the Numpy-discussion
mailing list