[Numpy-discussion] Profiling numpy ? (parts written in C)

David Cournapeau david at ar.media.kyoto-u.ac.jp
Tue Dec 19 20:36:15 CST 2006


Francesc Altet wrote:
> A Dimarts 19 Desembre 2006 08:12, David Cournapeau escrigué:
>> Hi,
>>
>>    Following the discussion on clip and other functions which *may* be
>> slow in numpy, I would like to know if there is a way to easily profile
>> numpy, ie functions which are written in C.
>>    For example, I am not sure to understand why a function like take(a,
>> b) with a a double 256x4 array and b a 8000x256 int array takes almost
>> 200 ms on a fairly fast CPU; in the source code, I can see that numpy
>> uses memmove, and I know memmove to be slower than memcpy. Is there an
>> easy way to check that this is coming from memmove (case in which
>> nothing much can be done to improve the situation I guess), and not from
>> something else ?
>
> For doing profiles on C extensions, you can use cProfile, which has
> been included in Python 2.5. See an example of your benchmark using
> cProfile below.
I haven't used python2.5 cprofile yet, mainly because of a really 
annoying bug of ubuntu with python2.5 and ctypes, which makes it 
unusable for me.

I totally forgot about ooprofile, which I tried once some time ago; I 
really like what I saw then. Thank you for the tip !

Concerning the memmove vs memcpy: the problem I was speaking about is in 
another function (numpy take), where the problem is much bigger speed wise.

I will be on holiday starting from tomorrow, with a big flight from 
Osaka to France, so I will have some time in the plane to investigate 
those :)

cheers,

David


More information about the Numpy-discussion mailing list