On Sun, Aug 23, 2009 at 10:38 PM, Robert Dodier<robert.dod...@gmail.com> wrote: > On 8/23/09, William Stein <wst...@gmail.com> wrote: > >> In fact, I am mildly surprised that the above two timings between ecl >> and maxima are so different. I wonder why it is an order of magnitude >> faster to compute "(+ 1 2)" than to compute "(MEVAL #$ 1 + 2$)". >> Perhaps in the second case the Maxima parser has to parse "1+2"? > > Well, the Maxima parser is slow, but also (MEVAL '((MPLUS) 1 2)) > goes through the simplifier, which eventually calls (+ 1 2) > as a special case. The simplifier attempts to apply various > identities, so it's really much more complex than just adding two > integers. I suppose that adding numbers is an important enough > special case that some effort could be spent trying to speed it up. > But most of the fun is in symbolic stuff, so that's probably why > it hasn't been done yet. > > Not sure in this case whether the parser or simplifier dominates. > >> Robert Dodier -- do you have any crazy ideas why Maxima might get >> slower to do the same thing over time? Is it caching all output >> somewhere? What other caching might be going on? > > This kind of stuff drives me nuts ... It appears the problem is > that Maxima is keeping a list of all input streams that have > ever been opened, and traversing the list every time an input > line is parsed. I'm guessing that Sage creates a little input file > each time it calls Maxima or something like that which creates > a new input stream every time. (In that case a work-around is > to avoid creating so many new input streams. Maybe open a > socket and send stuff through that?)
Wow, many thanks for looking into this!! Regarding your hypothesis, in theory I do not think Sage does any such thing. When Sage uses Maxima via pexpect, the *only* thing it does is type expressions in via the tty. This is *exactly* the same as when you use Maxima. Maxima absolutely cannot tell the difference between you using it and Sage using it. Here's a picture: Sage <----> Pseudotty <---> Maxima You <-----> Bash/ssh/Pseudotty <---> Maxima There is one exception -- if Sage is going to send some huge input to Maxima, it will write it to a file, then tell Maxima (via the tty) to read in that file. That is orthogonal to our problem. > That is in the code which annotates input with > debugging info. Try this: either edit maxima/src/nparse.lisp > and clobber the existing definition of ADD-LINEINFO with: > > (defun add-lineinfo (x) x) OK, I'm testing this now. I made this the last line of nparse.lisp. The result -- no go. Any other ideas? Anything I can add in debug wise? I wonder if there is a way for us to recreate this outside of Sage... that's the other thing I can try I guess. ./sage -f maxima-5.16.3.p3.spkg ... real 3m18.849s user 2m34.570s sys 0m37.220s Successfully installed maxima-5.16.3.p3 You can safely delete the temporary build directory /scratch/wstein/build/sage-4.1/spkg/build/maxima-5.16.3.p3 Making Sage/Python scripts relocatable... Making script relocatable Finished installing maxima-5.16.3.p3.spkg wst...@sage:~/build/sage-4.1$ ./sage ---------------------------------------------------------------------- | Sage Version 4.1, Release Date: 2009-07-09 | | Type notebook() for the GUI, and license() for information. | ---------------------------------------------------------------------- Loading Sage library. Current Mercurial branch is: ref3 sage: timeit('maxima.eval("2+2")') 5 loops, best of 3: 565 µs per loop sage: timeit('maxima.eval("2+2")') 625 loops, best of 3: 1.18 ms per loop sage: timeit('maxima.eval("2+2")') 125 loops, best of 3: 2.86 ms per loop sage: timeit('maxima.eval("2+2")') 125 loops, best of 3: 3.87 ms per loop Argh! William --~--~---------~--~----~------------~-------~--~----~ To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---