Hi Mike,

On Sun, Nov 24, 2013 at 10:46 AM, Mike Croucher
<[email protected]> wrote:
> Hi
>
> I'd like to time how long it takes sympy to evaluate 1 million digits of pi
> using ipython.  I've tried in both Linux and Windows.
> Let's look at the linux one for now
>
> import sympy
> #This command takes quite a while
> pi=sympy.pi.evalf(1000000)
> #This command evaluates instantly
> pi=sympy.pi.evalf(1000000)

I don't have gmpy installed, so I tested on 100,000:

In [1]: %time s = pi.evalf(100000)
CPU times: user 0.81 s, sys: 0.00 s, total: 0.81 s
Wall time: 0.81 s

In [2]: %time s = pi.evalf(100000)
CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
Wall time: 0.00 s

In [3]: %timeit s = pi.evalf(100000)
10000 loops, best of 3: 129 us per loop

>
> I suspected that sympy was caching the result so I did
>
> export SYMPY_USE_CACHE=no
>
> at the bash prompt before running ipython.  I also tried
>
> export SYMPY_USE_CACHE="no"
>
> either way, same result.

The above caching is done in mpmath. If you apply the following patch:

diff --git a/sympy/mpmath/libmp/libelefun.py b/sympy/mpmath/libmp/libelefun.py
index 531a7d4..1da0336 100644
--- a/sympy/mpmath/libmp/libelefun.py
+++ b/sympy/mpmath/libmp/libelefun.py
@@ -93,8 +93,8 @@ def constant_memo(f):
     f.memo_val = None
     def g(prec, **kwargs):
         memo_prec = f.memo_prec
-        if prec <= memo_prec:
-            return f.memo_val >> (memo_prec-prec)
+#        if prec <= memo_prec:
+#            return f.memo_val >> (memo_prec-prec)
         newprec = int(prec*1.05+10)
         f.memo_val = f(newprec, **kwargs)
         f.memo_prec = newprec


Then I get:

In [1]: %time s = pi.evalf(100000)
CPU times: user 0.81 s, sys: 0.00 s, total: 0.81 s
Wall time: 0.81 s

In [2]: %time s = pi.evalf(100000)
CPU times: user 0.81 s, sys: 0.00 s, total: 0.81 s
Wall time: 0.81 s

In [3]: %timeit s = pi.evalf(100000)
1 loops, best of 3: 802 ms per loop


>  Similarly if I try in windows using Windows
> environment variables and ipython via anaconda python.
>
> This is messing up %timeit
>
> What am I doing wrong please?

Nothing, you were just turning off the cache in SymPy, while
the numerical value of pi was being cached in sympy.mpmath.

Ondrej

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to