Skip to content
This repository has been archived by the owner on Jun 9, 2020. It is now read-only.

Set number of times to run function with line_profiler #42

Closed
jakirkham opened this issue Dec 18, 2015 · 6 comments
Closed

Set number of times to run function with line_profiler #42

jakirkham opened this issue Dec 18, 2015 · 6 comments

Comments

@jakirkham
Copy link

It might be nice to get some better statistics to set some number of times to run the function like what is done with timeit. This way if there is some drift from run to run it will hopefully cancel out on the average. This would also allow for some error bars to be added. If there is already a way to do this, please let me know.

Also, thanks for such an awesome tool. This is my favorite Python profiling tool by far.

@rkern
Copy link
Owner

rkern commented Dec 18, 2015

If you just run the function a number of times, the timings will all accumulate. LineProfiler itself will not do this because it is designed to work in situ and not just for top-level functions.

@jakirkham
Copy link
Author

Are you meaning that I should use kernprof instead?

@rkern
Copy link
Owner

rkern commented Dec 22, 2015

The use of kernprof as the runner script is independent of my recommendation here.

Just run the profiled function in a short loop if you need it profiled multiple times:

@profile
def f():
    ...

for i in range(10):
    f()

However you run LineProfiler, through kernprof, %lprun, or manual API usage, you should be able to do that.

@jakirkham
Copy link
Author

Ah, ok, thanks for clarifying.

@jakirkham
Copy link
Author

Though it is easy for me to get something similar by adding some more code on my side, I still think it would be nice to see this as an option for the line profiler.

@rkern
Copy link
Owner

rkern commented Dec 22, 2015

The reasoning I have given still stands. That functionality does not fit with the other requirements for LineProfiler.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants