[Numpy-discussion] line_profiler suggestion

Robert Kern robert.kern@gmail....
Wed Jan 21 15:44:26 CST 2009


On Wed, Jan 21, 2009 at 15:35, Neal Becker <ndbecker2@gmail.com> wrote:
> Robert Kern wrote:
>
>> On Wed, Jan 21, 2009 at 15:13, Neal Becker <ndbecker2@gmail.com> wrote:
>>> Would be handy to not have to add/remove @profile to switch between
>>> profiling/normal operation.
>>>
>>> When run without profiler, @profile is redefined to do nothing.
>>> Possible?
>>
>> I could add a --noop flag to kernprof, which basically tells it to
>> insert a do-nothing profile() decorator. I'm not sure what the use
>> case is, though. Are you switching back and forth frequently?
>>
> That won't help, the idea is to not have to edit the code adding/removing
> @profile in order to run _without_ kernprof.

In your code, you can conditionally insert a profile() decorator into
the __builtins__ if one isn't already there. You'll have to do that
before you import anything.

-- 
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