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 here http://docs.cython.org/src/quickstart/build.html you may
find something familiar)

-- 
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

Reply via email to