First time here? Check out the FAQ!

Ask Your Question
4

Profiling code in the Sage notebook

asked 13 years ago

benjaminfjones gravatar image

How can one profile Sage code in the notebook? I know you can use %prun <command> on the command line, but I understand this is a feature of IPython so it's not available in the notebook. I've looked (and searched) through the reference manual, sage-devel, and asksage to no avail.

Preview: (hide)

3 Answers

Sort by » oldest newest most voted
2

answered 8 years ago

tmonteil gravatar image

There is now a thematic tutorial listing profiling tools for Sage: http://doc.sagemath.org/html/en/thema...

Preview: (hide)
link
1

answered 13 years ago

benjaminfjones gravatar image

I found that the Python profiler will do the job: http://docs.python.org/library/profil...

It would be cool if there was an easy way to get the notebook to display some kind of data visualization based on the statistics from the python profiler, like the way one can see lines highlighted and colored in the notebook when working with Cython code.

Preview: (hide)
link
1

answered 13 years ago

pang gravatar image

Just for reference, here's a snippet on how to use cProfile:

import cProfile, pstats
cProfile.runctx("your_function(10000)", globals(), locals(), DATA + "Profile.prof")
s = pstats.Stats(DATA + "Profile.prof")
s.strip_dirs().sort_stats("time").print_stats()
Preview: (hide)
link

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 13 years ago

Seen: 1,553 times

Last updated: Apr 04 '16