Python profiling: using line_profiler @profile constructor results in an error
I am trying to profile Python code using a module line_profiler
, but I cannot get it to work. I am on Windows 7 and using Python 2.7.6.
When run kernprof -l -v test.py
in the following file test.py
:
@profile
def test():
a = 1
b = 1
return a + b
if __name__ == '__main__':
print test()
I get:
C:\>kernprof -l -v C:\test.py
Wrote profile results to test.py.lprof
Timer unit: 3.01262e-07 s
Traceback (most recent call last):
File "C:\path_to_kernprof\kernprof-script.py", line 10, in <module>
sys.exit(main())
File "C:\path_to_kernprof\kernprof.py", line 221, in main
execfile(script_file, ns, ns)
File "C:\test.py", line 1, in <module>
@profile
NameError: name 'profile' is not defined
Obviously, the code will work fine if I comment out the line containing line_profiler
@profile decorator. What am I doing wrong, here?
+3
user1461325
source
to share
3 answers