Ask Your Question
4

Profiling code in the Sage notebook

asked 2011-08-06 14:12:47 +0100

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.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
2

answered 2016-04-04 21:54:29 +0100

tmonteil gravatar image

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

edit flag offensive delete link more
1

answered 2011-08-06 18:42:33 +0100

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.

edit flag offensive delete link more
1

answered 2012-01-17 09:36:21 +0100

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()
edit flag offensive delete link more

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: 2011-08-06 14:12:47 +0100

Seen: 1,503 times

Last updated: Apr 04 '16