#11332: 65x penalty in performance for using float instead of RealNumber
---------------------------+------------------------------------------------
Reporter: pang | Owner: tbd
Type: defect | Status: new
Priority: major | Milestone: sage-4.7.1
Component: performance | Keywords: float, RealNumber
Work_issues: | Upstream: N/A
Reviewer: | Author:
Merged: | Dependencies:
---------------------------+------------------------------------------------
Comment(by nbruin):
note that "float" is the standard python float type, whereas RealNumber is
a preferred type for sage. Furthermore, "exp" is a general sage function
that can do all kinds of "exponentiation" (symbolic, numeric etc.), and
that incurs overhead. Apparently a particularly bad one for "float" types.
Setting the base line:
{{{
sage: x=random()
sage: y=RealNumber(x)
sage: z=RDF(x)
sage: timeit('exp(x)')
625 loops, best of 3: 1.15 ms per loop
sage: timeit('exp(y)')
625 loops, best of 3: 10.3 µs per loop
sage: timeit('exp(z)')
625 loops, best of 3: 3.52 µs per loop
}}}
Using python's own "exp" is the fastest:
{{{
sage: timeit('math.exp(x)')
625 loops, best of 3: 373 ns per loop
}}}
You can shave off some time from the RealNumber one too by calling a
method specific for it. It's slower, but RealNumber has much more
functionality (also multiprecision)
{{{
sage: timeit('y.exp()')
625 loops, best of 3: 6.28 µs per loop
}}}
RDF is supposed to be Sage's version of "double precision floats" and is
indeed comparable:
{{{
sage: timeit('z.exp()')
625 loops, best of 3: 704 ns per loop
}}}
If you don't mind a float, math.exp seems to receive a fairly efficiently
coerced float from either RealNumber or RDF
{{{
sage: timeit('math.exp(y)')
625 loops, best of 3: 510 ns per loop
sage: timeit('math.exp(z)')
625 loops, best of 3: 419 ns per loop
}}}
It would be nice if the generic "exp" would find a bit faster codepaths
for some of these types, but I wouldn't consider the current behaviour a
"defect".
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11332#comment:2>
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.