Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6211 > unrolled thread

Re: Hotshoting recursive function

Started by"Gabriel Genellina" <gagsl-py2@yahoo.com.ar>
First post2011-05-25 05:50 -0300
Last post2011-05-25 05:50 -0300
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Hotshoting recursive function "Gabriel Genellina" <gagsl-py2@yahoo.com.ar> - 2011-05-25 05:50 -0300

#6211 — Re: Hotshoting recursive function

From"Gabriel Genellina" <gagsl-py2@yahoo.com.ar>
Date2011-05-25 05:50 -0300
SubjectRe: Hotshoting recursive function
Message-ID<mailman.2060.1306313281.9059.python-list@python.org>
En Sun, 22 May 2011 10:42:08 -0300, Selvam <s.selvamsiva@gmail.com>  
escribió:

> I am using  hotshot module to profile my python function.
>
> I used the details from (
> http://code.activestate.com/recipes/576656-quick-python-profiling-with-hotshot/
> ).
>
> The function I profile is a recursive one and I am getting the following
> error,
>
> "ProfilerError: profiler already active"
>
> I guess this is due to the recursive call to the profiling function.
>
> I would like to get some suggestions.

The recursive call inside your function should call the undecorated  
function, not the decorated function again. Decorator syntax is not  
convenient anymore.

Using the same names as in the recipe example:


# a recursive function
def my_slow_function(n):
   ...
   return my_slow_function(n-1)


my_profiled_slow_function = hotshotit(my_slow_function)
my_profiled_slow_function(n)


This works, in the sense that it does not raise ProfileError anymore.  
Interpreting profile data is up to you...


-- 
Gabriel Genellina

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web