-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: %%lprun cell magic #42
Comments
I would really encourage people not to use cell magic. Its nice for IPython and Jupyter, but it makes it harder to port your code to simple scripts. You can almost always accomplish magic with normal Python syntax. For instance: def profile_now(func):
"""
Eagerly report profile information after each call to `func`.
Args:
func (Callable): function to profile
Example:
>>> # xdoctest: +SKIP
>>> def func_to_profile():
>>> list(range(10))
>>> tuple(range(100))
>>> set(range(1000))
>>> profile_now(func_to_profile)() # xdoctest: +IGNORE_WANT
Total time: 3.8e-05 s
Function: func_to_profile at line 1
Line # Hits Time Per Hit % Time Line Contents
==============================================================
1 def func_to_profile():
2 1 4.0 4.0 10.5 list(range(10))
3 1 3.0 3.0 7.9 tuple(range(100))
4 1 31.0 31.0 81.6 set(range(1000))
"""
import line_profiler
profile = line_profiler.LineProfiler()
new_func = profile(func)
new_func.profile_info = KernprofParser(profile)
new_func.print_report = new_func.profile_info.print_report
def wraper(*args, **kwargs):
retval = new_func(*args, **kwargs)
new_func.print_report()
return retval
wraper.new_func = new_func
return wraper https://github.com/Erotemic/xdev/blob/master/xdev/profiler.py#L44 |
@Erotemic: I agree that magics do not belong into scripts, but I believe that is irrelevant here. When porting code from a notebook to a script, very rarely should line-profiling even be in there - neither with nor without magic. On the other hand, if I have a notebook cell in my interactive work that takes too long, just dumping |
This would be a very useful feature to have when running interactively in a jupyter notebook. |
Hello all,
this is a copy of an issue from the old repo:
rkern/line_profiler#142
rkern/line_profiler#31
Two people already made a "hacky" implementations:
https://gist.github.com/auneri/54600375aa0317b9c47e
https://github.com/jdanbrown/potoo/blob/a7cc6a9/potoo/lprun_cell_magic.py
This feature would be really cool to see! The code from the second link is MIT licensed. Unfortunately I cant ping the original author here.
The text was updated successfully, but these errors were encountered: