On Sat, Nov 15, 2008 at 10:20 AM, Jason Grout <[EMAIL PROTECTED]> wrote: > > pong wrote: >> >> I have turned some codes that I have from PARI/GP into SAGE script but >> I find that they are order of magnitude slower than the original >> codes. Both types of codes are complied (i.e. I have .run in PARI and >> spyx files for SAGE) and running on the same machine. >> >> I am sure that's because I don't know enough of SAGE/Python to make >> them fast (e.g. log(RDF(2)) seems to be faster than log(float(2))). In >> general, if I want to do some simply arithmetic operations fast, >> what's the way to go with SAGE? Is sage.ext.arith the module that I >> should use? >> >> I couldn't find help on using fast_arith from the SAGE documentation >> so any examples and pointers are appreciated. > > > Posting some specific snippets that we can help with will probably get > better answers that queries for general advice. > > That is curious about the log(RDF(2)) compared to log(float(2)). What > about math.log(float(2))? That is pretty much the C log function being > called on a C float. (You might have to import math first). Here are > the timings: > > sage: a=RDF(2) > sage: %timeit b=log(a) > 1000000 loops, best of 3: 1.71 µs per loop > sage: a=float(2) > sage: %timeit b=log(a) > 100000 loops, best of 3: 10.4 µs per loop > sage: from math import log > sage: %timeit b=log(a) > 1000000 loops, best of 3: 643 ns per loop >
By the way, math.log is also just as fast on RDF's as on floats, at least on my OS X box (see the last two timings below): sage: a = RDF(2) sage: timeit('log(a)') 625 loops, best of 3: 4.98 µs per loop sage: a = float(2) sage: timeit('log(a)') 625 loops, best of 3: 7.68 µs per loop sage: from math import log sage: a = float(2) sage: timeit('log(a)') 625 loops, best of 3: 619 ns per loop sage: a = RDF(2) sage: timeit('log(a)') 625 loops, best of 3: 613 ns per loop --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---