On Wed, Apr 13, 2011 at 5:34 AM, Martin Rubey <martin.ru...@math.uni-hannover.de> wrote: > Hi there! > > I'd like to profile some performance-critical cythonized sage code. I > read that this can be done by writing > > # cython: profile=True > > at the very beginning of my file (which is configs.spyx). However, I > have the suspicion that this does not work entirely. > > I get the following without "# cython: profile=True" > > sage: %prun print len([i for i in I]) > 18480 > 129364 function calls in 41.181 CPU seconds > > Ordered by: internal time > > ncalls tottime percall cumtime percall filename:lineno(function) > 18480 40.185 0.002 40.185 0.002 > {_home_martin_martin_TeXSource_Mathematik_configs_spyx_13.children} > 18481 0.869 0.000 41.136 0.002 backtrack.py:810(__iter__) > 1 0.045 0.045 41.181 41.181 <string>:1(<module>) > 18480 0.034 0.000 40.219 0.002 <ipython console>:1(<lambda>) > 36958 0.024 0.000 0.024 0.000 {method 'add' of 'set' objects} > 18482 0.012 0.000 0.012 0.000 {len} > 18480 0.011 0.000 0.011 0.000 {method 'pop' of 'set' objects} > 1 0.000 0.000 0.000 0.000 {method 'copy' of 'set' objects} > 1 0.000 0.000 0.000 0.000 {method 'disable' of > '_lsprof.Profiler' objects} > > and roughly the same with "# cython: profile=True": > > sage: %prun print len([i for i in I]) > 18480 > 129364 function calls in 40.860 CPU seconds > > Ordered by: internal time > > ncalls tottime percall cumtime percall filename:lineno(function) > 18480 39.885 0.002 39.885 0.002 > {_home_martin_martin_TeXSource_Mathematik_configs_spyx_13.children} > 18481 0.852 0.000 40.817 0.002 backtrack.py:810(__iter__) > 1 0.044 0.044 40.860 40.860 <string>:1(<module>) > 18480 0.032 0.000 39.918 0.002 <ipython console>:1(<lambda>) > 36958 0.024 0.000 0.024 0.000 {method 'add' of 'set' objects} > 18482 0.012 0.000 0.012 0.000 {len} > 18480 0.011 0.000 0.011 0.000 {method 'pop' of 'set' objects} > 1 0.000 0.000 0.000 0.000 {method 'copy' of 'set' objects} > 1 0.000 0.000 0.000 0.000 {method 'disable' of > '_lsprof.Profiler' objects} > > In particular, the function children calls several subroutines, so I'd expect > to see them here... > > What am I doing wrong?
It's really hard to diagnose without seeing some code, but my guess is that either 1) The methods called in children are not in a python file compiled with #cython: profile=True 2) The spyx file gets a header prepended, meaning that the #cython ... pragmas are not at the top of the file anymore, and so are not applied. (Similar issues happen with __future__ imports). or both. - Robert -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org