On Aug 23, 1:58 pm, William Stein <wst...@gmail.com> wrote: > To whet our appetite though, might you do some benchmarks that compare > the speed of adding 2+2 via the library and via pexpect?
OK, here's a little experiment. I thought adding 2 and 2 would be too hard for now, so I stuck with 1+2. Good news is that all routines arrived at the correct answer. I did count the conversions back and forth every time as well, so times are not so very low. The conversions are completely string based, so I think performance can be quite a bit better still. Anyway, results: ecl/library (+ 2 2): 27.6 µs per loop maxima/library(+ 2 2): 134 µs per loop maxima/pexpect(+ 2 2): 4.97 ms per loop python/strings(2+2): 14 µs per loop So yes, library access does work a little better than pexpect. code used: sage: from sage.libs.ecl import * sage: init_ecl() sage: ecl_eval("(require 'asdf)") ;;; Loading #P"/home/wstein/build/sage-4.1.1/local/lib/ecl-9.4.1/ asdf.fas" ;;; Loading #P"/home/wstein/build/sage-4.1.1/local/lib/ecl-9.4.1/ cmp.fas" ;;; Loading #P"/home/wstein/build/sage-4.1.1/local/lib/ecl-9.4.1/ sysfun.lsp" <ECL: ("ASDF" "CMP") > sage: ecl_eval('(load "%s")'%(SAGE_ROOT+"/local/lib/maxima/ maxima.fasb")) ;;; Loading "/scratch/nbruin/sage-4.1.1-ecl-x86_64-Linux/local/lib/ maxima/maxima.fasb" <ECL: #P"/scratch/nbruin/sage-4.1.1-ecl-x86_64-Linux/local/lib/maxima/ maxima.fasb" > sage: ecl_eval('(in-package :maxima)') <ECL: #<"MAXIMA" package> > sage: sage: def ecladd(a,b): ....: return eval(str(ecl_eval('(+ %s %s)'%(a,b)))); ....: sage: def libadd(a,b): ....: return eval(str(ecl_eval('(MEVAL #$ %s + %s$)'%(a,b)))) ....: sage: def maxadd(a,b): ....: return (maxima(a)+maxima(b)).sage() ....: sage: def pythadd(a,b): ....: return eval("%s + %s"%(a,b)) ....: sage: timeit("ecladd(1,2)") 625 loops, best of 3: 27.6 µs per loop sage: timeit("libadd(1,2)") 625 loops, best of 3: 134 µs per loop sage: timeit("maxadd(1,2)") 5 loops, best of 3: 4.97 ms per loop sage: timeit("pythadd(1,2)") 625 loops, best of 3: 14 µs per loop --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---