Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Speedup commonly used Sage functions?

Hi,

Sage has many nice shorthand functions. This makes programming easy (to read, to debug). But it comes with a price! For instance:

def test1():

for k in xmrange([100]*3): return k

def test2():

for k1 in xrange(100):
    for k2 in xrange(100):
        for k3 in xrange(100): 
            return [k1,k2,k3]

timeit('test1()')

timeit('test2()')

625 loops, best of 3: 45.9 µs per loop

625 loops, best of 3: 1.59 µs per loop

Four questions:

  • Can we inform users that "it comes with a price?"

  • Can we speed up common, often used functions (easily)?

  • For more advanced users, can we provide them with a Cython equivalent? (named for instance cxmrange)

  • Maybe there is a better approach I'm not aware of?
click to hide/show revision 2
No.2 Revision

Speedup commonly used Sage functions?

Hi,

Sage has many nice shorthand functions. This makes programming easy (to read, to debug). But it comes with a price! For instance:

def test1():

def test1():

    for k in xmrange([100]*3): return k

def test2():

test2():

    for k1 in xrange(100):
     for k2 in xrange(100):
         for k3 in xrange(100): 
             return [k1,k2,k3]

timeit('test1()')

timeit('test2()')

625 timeit('test1()') timeit('test2()') >>625 loops, best of 3: 45.9 µs per loop

625 loop >>625 loops, best of 3: 1.59 µs per loop

loop

Four questions:

  • Can we inform users that "it comes with a price?"

  • Can we speed up common, often used functions (easily)?

  • For more advanced users, can we provide them with a Cython equivalent? (named for instance cxmrange)

  • Maybe there is a better approach I'm not aware of?
click to hide/show revision 3
retagged

Speedup commonly used Sage functions?

Hi,

Sage has many nice shorthand functions. This makes programming easy (to read, to debug). But it comes with a price! For instance:

def test1():

    for k in xmrange([100]*3): return k

def test2():

    for k1 in xrange(100):
        for k2 in xrange(100):
            for k3 in xrange(100): 
                return [k1,k2,k3]

timeit('test1()')

timeit('test2()')

>>625 loops, best of 3: 45.9 µs per loop
>>625 loops, best of 3: 1.59 µs per loop

Four questions:

  • Can we inform users that "it comes with a price?"

  • Can we speed up common, often used functions (easily)?

  • For more advanced users, can we provide them with a Cython equivalent? (named for instance cxmrange)

  • Maybe there is a better approach I'm not aware of?