#6199: Integer * int is slow
-------------------------------+--------------------------------------------
Reporter: fredrik.johansson | Owner: somebody
Type: defect | Status: needs_info
Priority: major | Milestone: sage-duplicate/invalid/wontfix
Component: basic arithmetic | Resolution:
Keywords: | Author:
Upstream: N/A | Reviewer:
Merged: | Work_issues:
-------------------------------+--------------------------------------------
Comment(by fredrik.johansson):
Thanks for working on this!
In mpmath, there are a lot of loops for fixed-point power series that
basically look something like:
{{{
prec = counter_type(150)
s = t = x = value_type(1) << prec
k = counter_type(1)
while t:
t = (t*x) >> prec
t = t*k//(4*k+1)
s += t
k += 1
}}}
Because Python ints are significantly faster than Integers for small
values and Integers are significantly faster than ints for large values,
it's optimal to use counter_type = int and value_type = Integer. (It's
even more optimal to Cythonize the same code, but I'm not there quite
yet.) Shift and division were already fixed.
> I'm leaning towards it being worth it, on the right only, for * and +
only.
Unfortunately I think it's equally common for the int to be on the left
(this can be fixed, but it's hard to track down where it happens).
Addition is not as important.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/6199#comment:7>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.