On Sep 9, 7:44 pm, cousteau <cousteaulecommand...@gmail.com> wrote: > On 9 sep, 18:24, David Harvey <dmhar...@cims.nyu.edu> wrote: > > > Sage is very slow. I discovered this (again) while trying to write a > > prototype of an algorithm for computing zeta functions of projective > > varieties. I need to multiply lots of polynomials and matrices over > > finite rings, and frequently move coefficients between polynomials > > and matrices. The arithmetic is actually not too bad; it's the boring > > data movement stuff that really sucks. > > Well, it's nothing new that Python is slower for low-level, highly > iterative functions (tight loops) than other languages such as C. > That's why part of the Sage source code is written in Cython rather > than Python. > > Sage can load (using load()) 3 file types: > - Sage (*.sage), a slightly modified version of the Python languages; > - Python (*.py); > - Cython (*.pyx), a sort of Python with some C declarations. > > Cython is way faster than Python, so if your code can be rewritten to > use Cython on the most CPU-intensive parts, it will be very fast. > > Example: > ----- py_iter.py ----- > def pyIter(n=20000000): > x = 1e-80 > for i in xrange(n): > x *= 1.000017 > print x > --- (time: 4.47 s) --- > > ----- cpy_iter.pyx ----- > cdef double _cpyIter_(long n): # C declaration > cdef double x = 1e-80 > cdef long i > for i in xrange(n): > x *= 1.000017 > return x > > def cpyIter(n=20000000): # Python declaration > return _cpyIter_(n) > --- (time: 0.06 s) --- > > You can find some documentation here:http://docs.cython.org/ > (Oh, and herehttp://docs.cython.org/src/quickstart/build.htmlyou may > find something familiar)
I am aware of all this. In fact I wrote a lot of the early Cython code in Sage (back when it was still Pyrex). The examples of slow things I gave are things that should be fast, even in the Sage interpreter. All of these things are fast in Magma for example, which is also an interpreted language, and this is the main reason that Magma is so popular in my research area (and clearly a reason that people would use Magma rather than Sage). I am using Sage to prototype my algorithm. I eventually intend to write a C++ version, once I have used the Sage version to experiment with the algorithm and understand it better. If the only way to write it in Sage is to work at a lower level then it completely defeats the purpose of using Sage to develop the prototype in the first place; I want to use Sage to hide the lower-level details so I can concentrate on the high level stuff. I don't care if it's a reasonable constant factor slower than what my fast implementation will eventually be. But a factor of 100x is unacceptable for these sorts of things, and makes it impossible to do experiments. david -- 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