numbers: speedup gcd
commitdcdb435cfa3c8642fb38fdb7c3e282422faa9707
authorKirill Smelkov <kirr@landau.phys.spbu.ru>
Sat, 9 Feb 2008 07:59:27 +0000 (9 10:59 +0300)
committerKirill Smelkov <kirr@landau.phys.spbu.ru>
Sat, 9 Feb 2008 07:59:27 +0000 (9 10:59 +0300)
tree1b7cd67f866d4fd587a0a98c939fec6139a546bb
parent6e7ccdd231f5e69ed7d06149b3fbc1a71193f5e3
numbers: speedup gcd

I think there is no reason to use @Memoizer for (almost) internal numbers.gcd .
In my view Memoizer is slow because at least it checks its args.

I propose we use direct approach in performance critical things -- direct cache
without typechecks. We can always wrap such caching with a decorator if we
find a way not to degrade performance.

Timing
------

from sympy.core.numbers import gcd as gcd_

      %timeit    %timeit      %timeit
      gcd_(1,1)  gcd_(23,17)  gcd_(60,3600)

old:  10.7 µs    10.7 µs      10.7 µs
new:  3.07 µs    3.07 µs      3.24 µs
sympy/core/numbers.py