Comment #8 on issue 1946 by asmeurer: Recursion error with SYMPY_GROUND_TYPES=sympy (caching problem)
http://code.google.com/p/sympy/issues/detail?id=1946

I can confirm your results:

In [11]: %timeit type(a) in (int, long)
1000000 loops, best of 3: 473 ns per loop

In [12]: %timeit type(b) in (int, long)
1000000 loops, best of 3: 477 ns per loop

In [13]: %timeit type(c) in (int, long)
100000 loops, best of 3: 3.03 us per loop

In [14]: %timeit type(d) in (int, long)
100000 loops, best of 3: 3.05 us per loop

In [15]: %timeit isinstance(a, (int, long))
1000000 loops, best of 3: 384 ns per loop

In [16]: %timeit isinstance(b, (int, long))
1000000 loops, best of 3: 727 ns per loop

In [17]: %timeit isinstance(c, (int, long))
1000000 loops, best of 3: 992 ns per loop

In [18]: %timeit isinstance(d, (int, long))
1000000 loops, best of 3: 988 ns per loop

It looks like isinstance just takes longer to short-circuit (according to the docstring, it's equivalent to
isinstance(a, int) or isinstance(b, long)):

In [22]: %timeit isinstance(a, (long, int))
1000000 loops, best of 3: 699 ns per loop

In [23]: %timeit isinstance(b, (long, int))
1000000 loops, best of 3: 402 ns per loop

In [24]: %timeit type(a) in (long, int)
1000000 loops, best of 3: 506 ns per loop

In [25]: %timeit type(b) in (long, int)
1000000 loops, best of 3: 415 ns per loop

As for mpz, in master I get:

In [9]: Integer(123) == mpz(123)
Out[9]: True

which is basically because sympify(mpz(123)) works (though it returns a Real!).

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

Reply via email to