ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 04 Apr 2016 14:54:29 -0500Profiling code in the Sage notebookhttp://ask.sagemath.org/question/8263/profiling-code-in-the-sage-notebook/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.Sat, 06 Aug 2011 07:12:47 -0500http://ask.sagemath.org/question/8263/profiling-code-in-the-sage-notebook/Answer by tmonteil for <p>How can one <em>profile</em> Sage code in the notebook? I know you can use <code>%prun <command></code> 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.</p>
http://ask.sagemath.org/question/8263/profiling-code-in-the-sage-notebook/?answer=32996#post-id-32996There is now a thematic tutorial listing profiling tools for Sage: http://doc.sagemath.org/html/en/thematic_tutorials/profiling.html#profiling
Mon, 04 Apr 2016 14:54:29 -0500http://ask.sagemath.org/question/8263/profiling-code-in-the-sage-notebook/?answer=32996#post-id-32996Answer by pang for <p>How can one <em>profile</em> Sage code in the notebook? I know you can use <code>%prun <command></code> 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.</p>
http://ask.sagemath.org/question/8263/profiling-code-in-the-sage-notebook/?answer=13132#post-id-13132Just 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()
Tue, 17 Jan 2012 02:36:21 -0600http://ask.sagemath.org/question/8263/profiling-code-in-the-sage-notebook/?answer=13132#post-id-13132Answer by benjaminfjones for <p>How can one <em>profile</em> Sage code in the notebook? I know you can use <code>%prun <command></code> 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.</p>
http://ask.sagemath.org/question/8263/profiling-code-in-the-sage-notebook/?answer=12558#post-id-12558I found that the Python profiler will do the job: http://docs.python.org/library/profile.html
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.Sat, 06 Aug 2011 11:42:33 -0500http://ask.sagemath.org/question/8263/profiling-code-in-the-sage-notebook/?answer=12558#post-id-12558