rkern / line_profiler

(OLD REPO) Line-by-line profiling for Python - Current repo ->
https://github.com/pyutils/line_profiler
Other
3.61k stars 255 forks source link

simplify "quick" profiling #39

Closed yarikoptic closed 8 years ago

yarikoptic commented 8 years ago

Thanks for the line_profilers -- does exactly what I needed: wanted to see what takes most of the time in the unittest. But to get such information I needed 4 lines at minimum...

+import line_profiler
+prof = line_profiler.LineProfiler()

+@prof
 def test_test():
@@ -108,10 +111,12 @@ 
      # end of the test_test
+    prof.print_stats()

I think it would be neat if I could just do

+from line_profiler import LineProfiler

+@LineProfiler(print_stats=True)
 def test_test()

to accomplish the mission, i.e. if decorator could just print those stats after completing the test.

rkern commented 8 years ago

That's what the kernprof script is for. You just need to add the @profile decorator to your own code, then.

yarikoptic commented 8 years ago

script is good when I can use script. In this case I needed to run the tests, i.e. invocation was like "nosetests -s -v codebase/tests/test_whaterver.py:test_test", so invoking it with a script (btw -- not installed under bin/ by pip install) I guess wouldn't be feasible, or am I wrong? also it would require two actions -- modifying the test code (doing already) and adjusting command line (instead of as suggested -- such adjusting the code)

rkern commented 8 years ago

kernprof -lv nosetests -s -v ...etc will work just fine. kernprof is smart enough to go through your $PATH to find the nosetests script.