[Numpy-discussion] python numpy code many times slower than c++

Robert Kern robert.kern at gmail.com
Tue Jan 20 21:52:41 EST 2009


On Tue, Jan 20, 2009 at 20:44, Neal Becker <ndbecker2 at gmail.com> wrote:
> Robert Kern wrote:
>
>> 2009/1/20 Neal Becker <ndbecker2 at gmail.com>:
>>> I tried a little experiment, implementing some code in numpy (usually I
>>> build modules in c++ to interface to python).  Since these operations are
>>> all large vectors, I hoped it would be reasonably efficient.
>>>
>>> The code in question is simple.  It is a model of an amplifier, modeled
>>> by it's AM/AM and AM/PM characteristics.
>>>
>>> The function in question is the __call__ operator.  The test program
>>> plots a spectrum, calling this operator 1024 times each time with a
>>> vector of 4096.
>>
>> If you want to find out what lines in that function are taking the
>> most time, you can try my line_profiler module:
>>
>> http://www.enthought.com/~rkern/cgi-bin/hgwebdir.cgi/line_profiler/
>>
>> That might give us a better idea in the absence of a self-contained
>> example.
>>
> Sounds interesting, I'll give that a try.  But, not sure how to use it.
>
> If my main script is plot_spectrum.py, and I want to profile the
> ampl.__call__ function (defined in ampl.py), what do I need to do?  I tried
> running kernprof.py plot_spectrum.py having added @profile decorators in
> ampl.py, but that didn't work:
>  File "../mod/ampl.py", line 43, in ampl
>    @profile
> NameError: name 'profile' is not defined

kernprof.py --line-by-line plot_spectrum.py

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list