First time here? Check out the FAQ!

Ask Your Question
0

Use @profile decorator in my script

asked 11 years ago

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!

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
0

answered 11 years ago

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.

Preview: (hide)
link
-1

answered 11 years ago

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!

Preview: (hide)
link

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 ( 11 years ago )

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 ( 11 years ago )

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

mresimulator gravatar imagemresimulator ( 11 years ago )

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

Luca gravatar imageLuca ( 11 years ago )

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: 11 years ago

Seen: 525 times

Last updated: Aug 20 '13