#15820: Implement sequences of bounded integers
--------------------------------------------+------------------------
Reporter: SimonKing | Owner:
Type: enhancement | Status: new
Priority: major | Milestone: sage-6.3
Component: algebra | Resolution:
Keywords: sequence bounded integer | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
Dependencies: | Stopgaps:
--------------------------------------------+------------------------
Comment (by SimonKing):
And here an example showing that it pays off, speed-wise:
In a .pyx file:
{{{
cimport cython
ctypedef fused str_or_int:
str
int
cpdef str_or_int times_two(str_or_int var):
if str_or_int is int:
return var*2
else:
return var+var
cpdef untyped_times_two(var):
return var*2
def test1():
cdef int a = 3
cdef str b = 'b'
a = times_two(a)
b = times_two(b)
def test2():
cdef int a = 3
cdef str b = 'b'
a = untyped_times_two(a)
b = untyped_times_two(b)
}}}
Attach the .pyx file to Sage, and get this:
{{{
age: %attach /home/king/Sage/work/templates/test.pyx
Compiling /home/king/Sage/work/templates/test.pyx...
sage: %timeit test1()
10000000 loops, best of 3: 164 ns per loop
sage: %timeit test2()
1000000 loops, best of 3: 264 ns per loop
}}}
--
Ticket URL: <http://trac.sagemath.org/ticket/15820#comment:40>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.