[Numpy-discussion] Speed performance on array constant set

Travis Oliphant oliphant.travis at ieee.org
Thu Jan 19 19:49:01 CST 2006


Mark Heslep wrote:

> 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
>
>
This is actually a bit surprising that opencv can create and fill so 
quickly.  Perhaps they are using  optimized SSE functions for the Intel 
platform, or something? 

-Travis









More information about the Numpy-discussion mailing list