Ask Your Question
0

Use @profile decorator in my script

asked 2013-08-19 22:26:39 +0100

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 08:02:01 +0100

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 09:45:04 +0100

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 18:23:41 +0100 )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 13:20:28 +0100 )edit

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

mresimulator gravatar imagemresimulator ( 2013-08-23 18:39:18 +0100 )edit

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

Luca gravatar imageLuca ( 2013-08-23 20:44:30 +0100 )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 22:26:39 +0100

Seen: 504 times

Last updated: Aug 20 '13