Ask Your Question
0

Use @profile decorator in my script

asked 2013-08-19 15:26:39 -0500

mresimulator gravatar image

Hi experts!!

I write a script like this:

 from scipy.stats import uniform    
 import numpy as np
 print ('lalala')
 LALA=[1,2,3,4,5]
 for j in LALA:
      algorithm (numpya arrays and other for and while cycles are invololved)

I have a RAM issue and i want to use @profile decorator. I install this for https://pypi.python.org/pypi/memory_p... doing:

 $ easy_install -U memory_profiler # pip install -U memory_profiler

But when i write @profile in the start of the code and then I execute this, i get a ERROR.

How can I do for use the @profile (and others) decoretor?

Waiting for your answers.

Thanks a lot!

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2013-08-20 01:02:01 -0500

Luca gravatar image

@profile is a function decorator, it can be only applied to a function or method. Wrap your code in a function and apply @profile to it, as shown in the examples of https://pypi.python.org/pypi/memory_profiler.

edit flag offensive delete link more
-1

answered 2013-08-20 02:45:04 -0500

mresimulator gravatar image

Thanks Luca!

For example, if my script is in folder '/home/PPP/script.sage'. Is this right?

1)

 def function_new():
      load('/home/PPP/script.sage')

2)

 @profile
 function_new()

By the way, if i wanna use @parallel decorator (for multicore proccesing), is it enought to do the next?

 @parallel
 function_new()

Waiting for your answers.

Thanks a lot!

edit flag offensive delete link more

Comments

Hi! Like this web shows, https://pypi.python.org/pypi/memory_profiler, the @profile docrator is designed for python (for example the script must be used doing $ python -m memory_profiler example.py). How can I do that in sage?? I create a new post for this. Thanks

mresimulator gravatar imagemresimulator ( 2013-08-20 11:23:41 -0500 )edit

Nope. This is right. @profile def my_function(): LALA=[1,2,3,4,5] for j in LALA: # algorithm (numpya arrays and other for and while cycles are invololved) You've already been told you shouldn't comment answers by "answering" in the box below. Use the "post a comment" feature instead. This way I get notified of your comments.

Luca gravatar imageLuca ( 2013-08-22 06:20:28 -0500 )edit

Ahhh... thanks!! Now works but @profiler accept xrange() but not accept srange(). Why?

mresimulator gravatar imagemresimulator ( 2013-08-23 11:39:18 -0500 )edit

I wouldn't know, maybe something to do with cython. Just guessing.

Luca gravatar imageLuca ( 2013-08-23 13:44:30 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-08-19 15:26:39 -0500

Seen: 182 times

Last updated: Aug 20 '13