line_profiler icon indicating copy to clipboard operation
line_profiler copied to clipboard

Profiling the same function multiple times

Open jrajagopal opened this issue 9 years ago • 3 comments
trafficstars

RIght now, I am calling a function multiple times as part of a loop. When I use line_profiler for this, it tells me that the number of hits for each line of the function is 1, which I would expect to be the number of times the loop is called.

First, am I getting that right? If so, how do I make line profiler give me execution times by function call?

jrajagopal avatar Aug 29 '16 23:08 jrajagopal

what could help is instantiating new LineProfiler object in each loop iteration.

for arr_length in range(r_limit, l_limit):
        line_prof = LineProfiler()
        line_prof.add_function(func_to_profile)
        func_to_profile(args)
        line_prof.dump_stats("{}_{}".format(func_to_profile.__name__, str(r_limit)))

petr-tik avatar Jul 17 '17 21:07 petr-tik

If that helps or not, please update the status of the issue

petr-tik avatar Jul 17 '17 21:07 petr-tik

@petr-tik missed this somehow - super late reply! Thanks :-)

jrajagopal avatar Oct 27 '17 19:10 jrajagopal