ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 04 Apr 2016 21:54:29 +0200Profiling code in the Sage notebookhttps://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 14:12:47 +0200https://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>
https://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 21:54:29 +0200https://ask.sagemath.org/question/8263/profiling-code-in-the-sage-notebook/?answer=32996#post-id-32996Answer 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>
https://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 18:42:33 +0200https://ask.sagemath.org/question/8263/profiling-code-in-the-sage-notebook/?answer=12558#post-id-12558Answer 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>
https://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 09:36:21 +0100https://ask.sagemath.org/question/8263/profiling-code-in-the-sage-notebook/?answer=13132#post-id-13132