> 6x speedup makes a big difference if you are going to make an
> evaluation thousands or even millions of times.

In fact, if you do the evaluation thousands or millions of times, the
difference will not be noticeable, because what will take long time is
the evaluation of the array inside numpy.sin, numpy.cos and numpy.add.
The difference between the two times is what is constant, not their
ratio.

In [22]: a = sin(x)+cos(x)

In [23]: b = lambdify(x, a, numpy)

In [24]: array_short = numpy.linspace(0,10,num=100)

In [25]: array_long = numpy.linspace(0,10,num=10000)

In [26]: %timeit a.eval_with_numpy(x, array_short)
10000 loops, best of 3: 65.9 us per loop

In [27]: %timeit a.eval_with_numpy(x, array_long)
1000 loops, best of 3: 1.05 ms per loop

In [28]: %timeit b(array_short)
100000 loops, best of 3: 15.7 us per loop

In [29]: %timeit b(array_long)
1000 loops, best of 3: 988 us per loop

As you can see it is a difference a constant of about 40us, not a ratio of 6x.

Another argument against the original benchmark: You did not take into
account the call to lambdify itself (in plotting, for example, the
lambdified expression is used only once (the new adaptive sampling
changes this)). The call to lambdify takes about as long as the
evaluation of the long array itself (10000 evaluations).

Of course, this is only true for numpy, not for python.math and
python.cmath. There one would indeed have 6x slowdown.

And all the discussion is about CPython, not something with a JIT like pypy.

In conclusion, there are some places where playing with closures will
be useful (all the non numpy stuff for instance), however there is no
obvious speed gain in the numpy case.

Although, I someone wants such a high performance, shouldn't he be
pointed to the autowrap cython and fortran implementations that we
have? This seems like a much cleaner solution (much less hacks).

Finally, if we implement the eval_with_numpy stuff, this will also
close issue 537 http://code.google.com/p/sympy/issues/detail?id=537

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" 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/sympy?hl=en.

Reply via email to