Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Benchmarks
COMMENTS:
Taken as a whole these benchmarks suggest that by far the fastest math software is MAGMA, Mathematica, and Sage (with appropriate tuning and choices -- it can also be very slow !). Maxima is very slow, at least in the form that comes with Sage (perhaps this is because of using clisp, at least partly). GP is slow at some thing and very fast at others.
TESTS::
sage: import sage.tests.benchmark """
""" Return the average of the list X.
EXAMPLES::
sage: from sage.tests.benchmark import avg sage: avg([1,2,3]) 2.0 """
""" A class for running specific benchmarks against different systems.
In order to implement an extension of this class, one must write functions named after the different systems one wants to test. These functions must perform the same task for each function. Calling the run command with a list of systems will then show the timings.
EXAMPLES::
sage: from sage.tests.benchmark import Benchmark sage: B = Benchmark() sage: def python(): ....: t = cputime() ....: n = 2+2 ....: return cputime(t) sage: B.python = python sage: B.run(systems=['python']) sage.tests.benchmark.Benchmark instance System min avg max trials cpu or wall * python ...
""" """ Run the benchmarking functions for the current benchmark on the systems given.
INPUT: systems -- list of strings of which systems to run tests on if None, runs the standard systems timeout -- how long (in seconds) to run each test for trials -- integer, number of trials sort -- whether to sort system names optional -- if systems is None, whether to test optional systems
EXAMPLES::
sage: from sage.tests.benchmark import PolyFactor sage: PolyFactor(10, QQ).run() Factor a product of 2 polynomials of degree 10 over Rational Field. System min avg max trials cpu or wall * sage ... * gp ...
""" systems.sort() #print "Timeout: %s seconds"%timeout 'avg', 'max', 'trials', 'cpu or wall')) systems += OPT_SYSTEMS wall = True t = t[1] mx, trials) s += '%15fw'%t else: print('%-12sinterrupted (timeout: %s seconds wall time)' % (S, timeout)) except Exception as msg: print(msg)
""" Print representation of self, simply coming from self.repr_str.
EXAMPLES::
sage: from sage.tests.benchmark import Benchmark sage: B = Benchmark() sage: B.repr_str = 'spam' sage: B spam """
""" Class for benchmarking computation of the division polynomial of the following elliptic curve.
EXAMPLES::
sage: E = EllipticCurve([1,2,3,4,5]) sage: E.division_polynomial(3) 3*x^4 + 9*x^3 + 33*x^2 + 87*x + 35 sage: E.division_polynomial(5) 5*x^12 + 45*x^11 + 422*x^10 + ... - 426371
sage: from sage.tests.benchmark import Divpoly sage: B = Divpoly(99) sage: B 99-Division polynomial """
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import Divpoly sage: B = Divpoly(3) sage: isinstance(B.sage(), float) True
"""
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import Divpoly sage: B = Divpoly(3) sage: isinstance(B.magma(), float) # optional - magma True
""" n = self.__n t = magma.cputime() m = magma('DivisionPolynomial(EllipticCurve([1,2,3,4,5]), %s)'%n) return magma.cputime(t)
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import PolySquare sage: B = PolySquare(3, QQ) sage: isinstance(B.sage(), float) True
"""
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import PolySquare sage: B = PolySquare(3, QQ) sage: isinstance(B.magma(), float) # optional - magma True
""" R = magma(self.__R) f = magma('PolynomialRing(%s)![1..%s]'%(R.name(),self.__n)) t = magma.cputime() g = f*f return magma.cputime(t)
""" Time the computation in Maple.
EXAMPLES::
sage: from sage.tests.benchmark import PolySquare sage: B = PolySquare(3, QQ) sage: isinstance(B.maple()[1], float) # optional - maple True
""" R = self.__R if not (R == ZZ or R == QQ): raise NotImplementedError n = self.__n f = maple(str(R['x'](range(1,n+1)))) t = walltime() g = f*f return False, walltime(t)
self.nvars - 1, self.exp, self.base)
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import MPolynomialPower sage: B = MPolynomialPower() sage: isinstance(B.sage()[1], float) True
""" t = cputime() w = z**self.exp return cputime(t)
""" Time the computation in Macaulay2.
EXAMPLES::
sage: from sage.tests.benchmark import MPolynomialPower sage: B = MPolynomialPower() sage: isinstance(B.macaulay2()[1], float) # optional - macaulay2 True
""" R = PolynomialRing(self.base, self.nvars, 'x') z = macaulay2(sum(R.gens())) t = walltime() w = z**self.exp return False, walltime(t)
""" Time the computation in Maxima.
EXAMPLES::
sage: from sage.tests.benchmark import MPolynomialPower sage: B = MPolynomialPower() sage: isinstance(B.maxima()[1], float) True
"""
""" Time the computation in Maple.
EXAMPLES::
sage: from sage.tests.benchmark import MPolynomialPower sage: B = MPolynomialPower() sage: isinstance(B.maple()[1], float) # optional - maple True
""" R = PolynomialRing(self.base, self.nvars, 'x') z = maple(str(sum(R.gens()))) w = walltime() f = (z**self.exp).expand() return False, walltime(w)
""" Time the computation in Mathematica.
EXAMPLES::
sage: from sage.tests.benchmark import MPolynomialPower sage: B = MPolynomialPower() sage: isinstance(B.mathematica()[1], float) # optional - mathematica True
""" R = PolynomialRing(self.base, self.nvars, 'x') z = mathematica(str(sum(R.gens()))) w = walltime() f = (z**self.exp).Expand() return False, walltime(w)
## this doesn't really expand out -- pari has no function to do so, ## as far as I know. ## def gp(self): ## R = PolynomialRing(self.base, self.nvars) ## z = gp(str(sum(R.gens()))) ## gp.eval('gettime') ## f = z**self.exp ## return float(gp.eval('gettime/1000.0'))
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import MPolynomialPower sage: B = MPolynomialPower() sage: isinstance(B.magma(), float) # optional - magma True
""" R = magma.PolynomialRing(self.base, self.nvars) z = R.gen(1) for i in range(2,self.nvars+1): z += R.gen(i) t = magma.cputime() w = z**magma(self.exp) return magma.cputime(t)
nvars += 1 self.nvars/2 - 1, self.nvars/2, self.nvars, self.base)
""" Time the computation in Maxima.
EXAMPLES::
sage: from sage.tests.benchmark import MPolynomialMult sage: B = MPolynomialMult() sage: isinstance(B.maxima()[1], float) True
"""
""" Time the computation in Maple.
EXAMPLES::
sage: from sage.tests.benchmark import MPolynomialMult sage: B = MPolynomialMult() sage: isinstance(B.maple()[1], float) # optional - maple True
""" R = PolynomialRing(self.base, self.nvars, 'x') k = self.nvars // 2 z0 = maple(str(sum(R.gens()[:k]))) z1 = maple(str(sum(R.gens()[k:]))) w = walltime() f = (z0*z1).expand() return False, walltime(w)
""" Time the computation in Mathematica.
EXAMPLES::
sage: from sage.tests.benchmark import MPolynomialMult sage: B = MPolynomialMult() sage: isinstance(B.mathematica()[1], float) # optional - mathematica True
""" R = PolynomialRing(self.base, self.nvars, 'x') k = self.nvars // 2 z0 = mathematica(str(sum(R.gens()[:k]))) z1 = mathematica(str(sum(R.gens()[k:]))) w = walltime() f = (z0*z1).Expand() return False, walltime(w)
## def gp(self): ## R = PolynomialRing(self.base, self.nvars) ## k = self.nvars // 2 ## z0 = gp(str(sum(R.gens()[:k]))) ## z1 = gp(str(sum(R.gens()[k:]))) ## gp.eval('gettime') ## f = z0*z1 ## return float(gp.eval('gettime/1000.0'))
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import MPolynomialMult sage: B = MPolynomialMult() sage: isinstance(B.sage()[1], float) True
""" else: t = cputime() w = z0 * z1 return cputime(t)
""" Time the computation in Macaulay2.
EXAMPLES::
sage: from sage.tests.benchmark import MPolynomialMult sage: B = MPolynomialMult() sage: isinstance(B.macaulay2()[1], float) # optional - macaulay2 True
""" R = PolynomialRing(self.base, self.nvars, 'x') k = self.nvars // 2 z0 = macaulay2(sum(R.gens()[:k])) z1 = macaulay2(sum(R.gens()[k:])) t = walltime() w = z0*z1 return False, walltime(t)
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import MPolynomialMult sage: B = MPolynomialMult() sage: isinstance(B.magma(), float) # optional - magma True
""" R = magma.PolynomialRing(self.base, self.nvars) z0 = R.gen(1) k = self.nvars // 2 for i in range(2,k+1): z0 += R.gen(i) z1 = R.gen(k + 1) for i in range(k+1, self.nvars + 1): z1 += R.gen(i) t = magma.cputime() w = z0 * z1 return magma.cputime(t)
nvars += 1 self.nvars/2, self.nvars/2, self.nvars/2+1, self.nvars/2+1, self.nvars+1, self.nvars+1, self.base)
## def gp(self): ## R = PolynomialRing(self.base, self.nvars) ## k = self.nvars // 2 ## z0 = R(0) ## z1 = R(0) ## for i in range(k): ## z0 += (i+1)*R.gen(i) ## for i in range(k,self.nvars): ## z1 += (i+1)*R.gen(i) ## z0 = gp(str(z0)) ## z1 = gp(str(z1)) ## gp.eval('gettime') ## f = z0*z1 ## print f ## return float(gp.eval('gettime/1000.0'))
""" Time the computation in Maxima.
EXAMPLES::
sage: from sage.tests.benchmark import MPolynomialMult2 sage: B = MPolynomialMult2() sage: isinstance(B.maxima()[1], float) True
"""
""" Time the computation in Macaulay2.
EXAMPLES::
sage: from sage.tests.benchmark import MPolynomialMult2 sage: B = MPolynomialMult2() sage: isinstance(B.macaulay2()[1], float) # optional - macaulay2 True
""" R = PolynomialRing(self.base, self.nvars, 'x') k = self.nvars // 2 z0 = R(0) z1 = R(0) for i in range(k): z0 += (i+1)*R.gen(i) for i in range(k,self.nvars): z1 += (i+1)*R.gen(i) z0 = macaulay2(z0) z1 = macaulay2(z1) t = walltime() w = z0*z1 return False, walltime(t)
""" Time the computation in Maple.
EXAMPLES::
sage: from sage.tests.benchmark import MPolynomialMult2 sage: B = MPolynomialMult2() sage: isinstance(B.maple()[1], float) # optional - maple True
""" R = PolynomialRing(self.base, self.nvars, 'x') k = self.nvars // 2 z0 = R(0) z1 = R(0) for i in range(k): z0 += (i+1)*R.gen(i) for i in range(k,self.nvars): z1 += (i+1)*R.gen(i) z0 = maple(str(z0)) z1 = maple(str(z1)) w = walltime() f = (z0*z1).expand() return False, walltime(w)
""" Time the computation in Mathematica.
EXAMPLES::
sage: from sage.tests.benchmark import MPolynomialMult2 sage: B = MPolynomialMult2() sage: isinstance(B.mathematica()[1], float) # optional - mathematica True
""" R = PolynomialRing(self.base, self.nvars, 'x') k = self.nvars // 2 z0 = R(0) z1 = R(0) for i in range(k): z0 += (i+1)*R.gen(i) for i in range(k,self.nvars): z1 += (i+1)*R.gen(i) z0 = mathematica(str(z0)) z1 = mathematica(str(z1)) w = walltime() f = (z0*z1).Expand() return False, walltime(w)
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import MPolynomialMult2 sage: B = MPolynomialMult2() sage: isinstance(B.sage()[1], float) True
""" else: t = cputime() w = z0 * z1 return cputime(t)
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import MPolynomialMult2 sage: B = MPolynomialMult2() sage: isinstance(B.magma(), float) # optional - magma True
""" R = magma.PolynomialRing(self.base, self.nvars) z0 = R.gen(1) k = self.nvars // 2 for i in range(2,k+1): z0 += magma(i)*R.gen(i) z1 = R.gen(k + 1) for i in range(k+1, self.nvars + 1): z1 += magma(i)*R.gen(i) t = magma.cputime() w = z0 * z1 return magma.cputime(t)
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import CharPolyTp sage: B = CharPolyTp() sage: isinstance(B.sage(), float) True
"""
""" Time the computation in GP.
EXAMPLES::
sage: from sage.tests.benchmark import CharPolyTp sage: B = CharPolyTp() sage: isinstance(B.gp(), float) True
"""
""" Time the computation in Pari.
EXAMPLES::
sage: from sage.tests.benchmark import CharPolyTp sage: B = CharPolyTp() sage: isinstance(B.pari(), float) True
"""
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import CharPolyTp sage: B = CharPolyTp() sage: isinstance(B.magma(), float) # optional - magma True
""" m = magma(self.matrix()) t = magma.cputime() f = m.CharacteristicPolynomial() return magma.cputime(t)
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import PolyFactor sage: B = PolyFactor(3, QQ) sage: isinstance(B.sage(), float) True
"""
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import PolyFactor sage: B = PolyFactor(3, QQ) sage: isinstance(B.magma(), float) # optional - magma True
""" R = magma(self.__R) f = magma('PolynomialRing(%s)![1..%s]'%(R.name(),self.__n)) g = magma('PolynomialRing(%s)![%s+1..2*(%s+1)]'%( R.name(),self.__n,self.__n)) h = f*g t = magma.cputime() h.Factorization() return magma.cputime(t)
""" Time the computation in GP.
EXAMPLES::
sage: from sage.tests.benchmark import PolyFactor sage: B = PolyFactor(3, QQ) sage: isinstance(B.gp(), float) True
"""
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import SquareInts sage: B = SquareInts() sage: isinstance(B.sage(), float) True
"""
""" Time the computation in GP.
EXAMPLES::
sage: from sage.tests.benchmark import SquareInts sage: B = SquareInts() sage: isinstance(B.gp(), float) True
"""
""" Time the computation in Maxima.
EXAMPLES::
sage: from sage.tests.benchmark import SquareInts sage: B = SquareInts() sage: isinstance(B.maxima()[1], float) True
"""
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import SquareInts sage: B = SquareInts() sage: isinstance(B.magma(), float) # optional - magma True
""" n = magma('%s^%s'%(self.base,self.__ndigits)) t = magma.cputime() m = n**2 return magma.cputime(t)
""" Time the computation in Python.
EXAMPLES::
sage: from sage.tests.benchmark import SquareInts sage: B = SquareInts() sage: isinstance(B.python(), float) True
"""
""" Time the computation in Maple.
EXAMPLES::
sage: from sage.tests.benchmark import SquareInts sage: B = SquareInts() sage: isinstance(B.maple()[1], float) # optional - maple True
""" n = maple('%s^%s'%(self.base,self.__ndigits)) t = walltime() m = n**2 return False, walltime(t)
""" Time the computation in GAP.
EXAMPLES::
sage: from sage.tests.benchmark import SquareInts sage: B = SquareInts() sage: isinstance(B.gap()[1], float) True
"""
""" Time the computation in Mathematica.
EXAMPLES::
sage: from sage.tests.benchmark import SquareInts sage: B = SquareInts() sage: isinstance(B.mathematica()[1], float) # optional - mathematica True
""" n = mathematica('%s^%s'%(self.base,self.__ndigits)) t = walltime() m = n**2 return False, walltime(t)
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import MatrixSquare sage: B = MatrixSquare(3, QQ) sage: isinstance(B.sage(), float) True
"""
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import MatrixSquare sage: B = MatrixSquare(3, QQ) sage: isinstance(B.magma(), float) # optional - magma True
""" R = magma(self.__R) f = magma('MatrixAlgebra(%s, %s)![0..%s^2-1]'%( R.name(),self.__n, self.__n)) t = magma.cputime() g = f*f return magma.cputime(t)
""" Time the computation in GP.
EXAMPLES::
sage: from sage.tests.benchmark import MatrixSquare sage: B = MatrixSquare(3, QQ) sage: isinstance(B.gp(), float) True
"""
""" Time the computation in GAP.
EXAMPLES::
sage: from sage.tests.benchmark import MatrixSquare sage: B = MatrixSquare(3, QQ) sage: isinstance(B.gap()[1], float) True
"""
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import Factorial sage: B = Factorial(10) sage: isinstance(B.sage(), float) True
"""
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import Factorial sage: B = Factorial(10) sage: isinstance(B.magma(), float) # optional - magma True
""" t = magma.cputime() n = magma('&*[1..%s]'%self.__n) # &* is way better than Factorial!! return magma.cputime(t)
""" Time the computation in Maple.
EXAMPLES::
sage: from sage.tests.benchmark import Factorial sage: B = Factorial(10) sage: isinstance(B.maple()[1], float) # optional - maple True
""" n = maple(self.__n) t = walltime() m = n.factorial() return False, walltime(t)
""" Time the computation in GP.
EXAMPLES::
sage: from sage.tests.benchmark import Factorial sage: B = Factorial(10) sage: isinstance(B.gp(), float) True
"""
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import Fibonacci sage: B = Fibonacci(10) sage: isinstance(B.sage(), float) True
"""
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import Fibonacci sage: B = Fibonacci(10) sage: isinstance(B.magma(), float) # optional - magma True
""" t = magma.cputime() n = magma('Fibonacci(%s)'%self.__n) return magma.cputime(t)
""" Time the computation in GAP.
EXAMPLES::
sage: from sage.tests.benchmark import Fibonacci sage: B = Fibonacci(10) sage: isinstance(B.gap()[1], float) True
"""
""" Time the computation in Mathematica.
EXAMPLES::
sage: from sage.tests.benchmark import Fibonacci sage: B = Fibonacci(10) sage: isinstance(B.mathematica()[1], float) # optional - mathematica True
""" n = mathematica(self.__n) t = walltime() m = n.Fibonacci() return False, walltime(t)
""" Time the computation in GP.
EXAMPLES::
sage: from sage.tests.benchmark import Fibonacci sage: B = Fibonacci(10) sage: isinstance(B.gp(), float) True
"""
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import SEA sage: B = SEA(5) sage: isinstance(B.sage()[1], float) True
""" # Note that from pari 2.4.3, the SEA algorithm is used by the # pari library, but only for large primes, so for a better # test a prime > 2^30 should be used and not 5. In fact # next_prime(2^100) works fine (<<1s).
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import SEA sage: B = SEA(5) sage: isinstance(B.magma(), float) # optional - magma True
""" magma(0) t = magma.cputime() m = magma('#EllipticCurve([GF(%s)|1,2,3,4,5])'%(self.__p)) return magma.cputime(t)
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import MatrixKernel sage: B = MatrixKernel(3, QQ) sage: isinstance(B.sage(), float) True
"""
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import MatrixKernel sage: B = MatrixKernel(3, QQ) sage: isinstance(B.magma(), float) # optional - magma True
""" R = magma(self.__R) f = magma('RMatrixSpace(%s, %s, %s)![0..(%s*2*%s)-1]'%( R.name(),self.__n, 2*self.__n, self.__n, self.__n)) t = magma.cputime() g = f.Kernel() return magma.cputime(t)
""" Time the computation in GP.
EXAMPLES::
sage: from sage.tests.benchmark import MatrixKernel sage: B = MatrixKernel(3, QQ) sage: isinstance(B.gp(), float) True
"""
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import ComplexMultiply sage: B = ComplexMultiply(28, 2) sage: isinstance(B.sage(), float) True
"""
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import ComplexMultiply sage: B = ComplexMultiply(28, 2) sage: isinstance(B.magma(), float) # optional - magma True
.. NOTE::
decimal digits (despite magma docs that say bits!!)
""" n = int(self.__bits_prec/log(10,2)) + 1 CC = magma.ComplexField(n) s = CC(2).Sqrt() + CC.gen(1).Sqrt() t = magma.cputime() magma.eval('s := %s;'%s.name()) v = magma('[s*s : i in [1..%s]]'%self.__times) return magma.cputime(t)
""" Time the computation in GP.
EXAMPLES::
sage: from sage.tests.benchmark import ComplexMultiply sage: B = ComplexMultiply(28, 2) sage: isinstance(B.gp(), float) True
"""
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import ModularSymbols1 sage: B = ModularSymbols1(11) sage: isinstance(B.sage(), float) True
"""
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import ModularSymbols1 sage: B = ModularSymbols1(11) sage: isinstance(B.magma(), float) # optional - magma True
""" magma = Magma() # new instance since otherwise modsyms are cached, and cache can't be cleared t = magma.cputime() M = magma('ModularSymbols(%s, %s)'%(self.__N, self.__k)) return magma.cputime(t)
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import ModularSymbolsDecomp1 sage: B = ModularSymbolsDecomp1(11) sage: isinstance(B.sage(), float) True
"""
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import ModularSymbolsDecomp1 sage: B = ModularSymbolsDecomp1(11) sage: isinstance(B.magma(), float) # optional - magma True
""" m = Magma() # new instance since otherwise modsyms are cached, and cache can't be cleared t = m.cputime() D = m.eval('Decomposition(ModularSymbols(%s, %s, %s),%s);'%( self.N, self.k, self.sign, self.bnd)) return m.cputime(t)
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import EllipticCurveTraces sage: B = EllipticCurveTraces(11) sage: isinstance(B.sage(), float) Traceback (most recent call last): ... TypeError: anlist() got an unexpected keyword argument 'pari_ints'
""" return cputime(t)
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import EllipticCurveTraces sage: B = EllipticCurveTraces(11) sage: isinstance(B.magma(), float) # optional - magma True
""" E = magma.EllipticCurve([1,2,3,4,5]) t = magma.cputime() v = E.TracesOfFrobenius(self.B) return magma.cputime(t)
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import EllipticCurvePointMul sage: B = EllipticCurvePointMul(11) sage: isinstance(B.sage(), float) True
"""
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import EllipticCurvePointMul sage: B = EllipticCurvePointMul(11) sage: isinstance(B.magma(), float) # optional - magma True
""" E = magma.EllipticCurve('[0, 0, 1, -1, 0]') P = E('[0,0]') t = magma.cputime() Q = magma(self.n) * P return magma.cputime(t)
""" Time the computation in GP.
EXAMPLES::
sage: from sage.tests.benchmark import EllipticCurvePointMul sage: B = EllipticCurvePointMul(11) sage: isinstance(B.gp(), float) True
"""
""" Time the computation in Pari.
EXAMPLES::
sage: from sage.tests.benchmark import EllipticCurvePointMul sage: B = EllipticCurvePointMul(11) sage: isinstance(B.pari(), float) True
"""
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import EllipticCurveMW sage: B = EllipticCurveMW([1,2,3,4,5]) sage: isinstance(B.sage()[1], float) True
"""
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import EllipticCurveMW sage: B = EllipticCurveMW([1,2,3,4,5]) sage: isinstance(B.magma(), float) # optional - magma True
""" E = magma.EllipticCurve(str(self.ainvs)) t = magma.cputime() G = E.Generators() return magma.cputime(t)
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import FiniteExtFieldMult sage: B = FiniteExtFieldMult(GF(9, 'x'), 2) sage: isinstance(B.sage(), float) True
"""
""" Time the computation in Pari.
EXAMPLES::
sage: from sage.tests.benchmark import FiniteExtFieldMult sage: B = FiniteExtFieldMult(GF(9, 'x'), 2) sage: isinstance(B.pari(), float) True
"""
""" Time the computation in Givaro.
EXAMPLES::
sage: from sage.tests.benchmark import FiniteExtFieldMult sage: B = FiniteExtFieldMult(GF(9, 'x'), 2) sage: isinstance(B.givaro(), float) Traceback (most recent call last): ... AttributeError: 'module' object has no attribute 'GFq'
""" e = k(self.e) f = k(self.f) t = cputime() v = [e*f for _ in range(self.__times)] return cputime(t)
""" Time the computation in Givaro.
TODO: nck?
EXAMPLES::
sage: from sage.tests.benchmark import FiniteExtFieldMult sage: B = FiniteExtFieldMult(GF(9, 'x'), 2) sage: isinstance(B.givaro_nck(), float) Traceback (most recent call last): ... AttributeError: 'module' object has no attribute 'GFq'
""" e = k(self.e) f = k(self.f) t = cputime() v = [e.mul(f) for _ in range(self.__times)] return cputime(t)
""" Time the computation in Givaro.
TODO: raw?
EXAMPLES::
sage: from sage.tests.benchmark import FiniteExtFieldMult sage: B = FiniteExtFieldMult(GF(9, 'x'), 2) sage: isinstance(B.givaro_raw(), float) Traceback (most recent call last): ... AttributeError: 'module' object has no attribute 'GFq'
""" e = k(self.e).logint() f = k(self.f).logint() t = cputime() v = [k._mul(e,f) for _ in range(self.__times)] return cputime(t)
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import FiniteExtFieldMult sage: B = FiniteExtFieldMult(GF(9, 'x'), 2) sage: isinstance(B.magma(), float) # optional - magma True
""" magma.eval('F<a> := GF(%s)'%(self.field.cardinality())) magma.eval('e := a^Floor(%s/3);'%(self.field.cardinality())) magma.eval('f := a^Floor(2*%s/3);'%(self.field.cardinality())) t = magma.cputime() v = magma('[e*f : i in [1..%s]]'%self.__times) return magma.cputime(t)
""" Time the computation in Sage.
EXAMPLES::
sage: from sage.tests.benchmark import FiniteExtFieldAdd sage: B = FiniteExtFieldAdd(GF(9,'x'), 2) sage: isinstance(B.sage(), float) True
"""
""" Time the computation in Pari.
EXAMPLES::
sage: from sage.tests.benchmark import FiniteExtFieldAdd sage: B = FiniteExtFieldAdd(GF(9,'x'), 2) sage: isinstance(B.pari(), float) True
"""
""" Time the computation in Givaro.
EXAMPLES::
sage: from sage.tests.benchmark import FiniteExtFieldAdd sage: B = FiniteExtFieldAdd(GF(9,'x'), 2) sage: isinstance(B.givaro(), float) Traceback (most recent call last): ... AttributeError: 'module' object has no attribute 'GFq'
""" e = k(self.e) f = k(self.f) t = cputime() v = [e+f for _ in range(self.__times)] return cputime(t)
""" Time the computation in Givaro.
TODO: nck?
EXAMPLES::
sage: from sage.tests.benchmark import FiniteExtFieldAdd sage: B = FiniteExtFieldAdd(GF(9,'x'), 2) sage: isinstance(B.givaro_nck(), float) Traceback (most recent call last): ... AttributeError: 'module' object has no attribute 'GFq'
""" e = k(self.e) f = k(self.f) t = cputime() v = [e.add(f) for _ in range(self.__times)] return cputime(t)
""" Time the computation in Givaro.
TODO: raw?
EXAMPLES::
sage: from sage.tests.benchmark import FiniteExtFieldAdd sage: B = FiniteExtFieldAdd(GF(9, 'x'), 2) sage: isinstance(B.givaro_raw(), float) Traceback (most recent call last): ... AttributeError: 'module' object has no attribute 'GFq'
""" e = k(self.e).logint() f = k(self.f).logint() t = cputime() v = [k._add(e,f) for _ in range(self.__times)] return cputime(t)
""" Time the computation in Magma.
EXAMPLES::
sage: from sage.tests.benchmark import FiniteExtFieldAdd sage: B = FiniteExtFieldAdd(GF(9,'x'), 2) sage: isinstance(B.magma(), float) # optional - magma True
""" magma.eval('F<a> := GF(%s)'%(self.field.cardinality())) magma.eval('e := a^Floor(%s/3);'%(self.field.cardinality())) magma.eval('f := a^Floor(2*%s/3);'%(self.field.cardinality())) t = magma.cputime() v = magma('[e+f : i in [1..%s]]'%self.__times) return magma.cputime(t)
""" TODO: * multiply reals * modular degree * anlist * MW group * symbolic det * poly factor * multivariate poly factor
"""
PolySquare(10000,QQ).run() PolySquare(20000,ZZ).run() PolySquare(50000,GF(5)).run() PolySquare(20000,Integers(8)).run()
SquareInts(10,2000000).run()
MatrixSquare(200,QQ).run() MatrixSquare(50,ZZ).run()
SquareInts(10,150000).run()
Factorial(2*10**6).run(systems = ['sage', 'magma']) Fibonacci(10**6).run() Fibonacci(2*10^7).run(systems=["sage", "magma", "mathematica"])
MatrixKernel(150,QQ).run()
ComplexMultiply(100000,1000) ComplexMultiply(100,100000) ComplexMultiply(53,100000)
PolyFactor(300,ZZ) PolyFactor(300,GF(19)) PolyFactor(700,GF(19))
PolyFactor(500,GF(49,'a')) PolyFactor(100,GF(10007^3,'a'))
CharPolyTp(54,4).run() CharPolyTp(389,2).run() CharPolyTp(389,2,sign=0,p=3).run() CharPolyTp(1000,2,sign=1,p=2).run(systems=['sage','magma']) CharPolyTp(1,100,sign=1,p=5).run(systems=['sage','magma']) # Sage's multimodular really sucks here! (GP is way better, even) CharPolyTp(512,sign=1,p=3).run(systems=['sage','magma','gp']) CharPolyTp(512,sign=0,p=3).run(systems=['sage','magma','gp']) CharPolyTp(1024,sign=1,p=3).run(systems=['sage','magma','gp']) CharPolyTp(2006,sign=1,p=2).run(systems=['sage','magma','gp']) CharPolyTp(2006,sign=1,p=2).run(systems=['sage','magma']) # gp takes > 1 minute.
# This includes a maxima benchmark. Note that # maxima is *shockingly* slow in comparison to Singular or MAGMA. # It is so slow as to be useless, basically, i.e., factor # of 5000 slower than Singular on this example! MPolynomialPower(nvars=6,exp=10).run()
main = ['sage', 'magma'] # just the main competitors MPolynomialPower(nvars=2,exp=200, allow_singular=False).run(main) MPolynomialPower(nvars=5,exp=10, allow_singular=False).run(main) MPolynomialPower(nvars=5,exp=30, allow_singular=True).run(main) MPolynomialPower(nvars=2,exp=1000, allow_singular=True).run(main) MPolynomialPower(nvars=10,exp=10, allow_singular=True).run(main) MPolynomialPower(nvars=4,exp=350, base=GF(7), allow_singular=True).run(main) MPolynomialMult(200, allow_singular=False).run(main) MPolynomialMult(400, allow_singular=True).run(main) MPolynomialMult(800, allow_singular=True).run(main) MPolynomialMult2(500, allow_singular=True).run(main)
""" Runs benchmarks for multipoly arithmetic on all systems (except Maxima, since it is very very slow). You must have mathematica, maple, and magma.
.. NOTE::
* maple is depressingly slow on these benchmarks. * Singular (i.e., Sage) does shockingly well. * mathematica is sometimes amazing. * macaulay2 is also quite bad (though not as bad as maple).
EXAMPLES::
sage: from sage.tests.benchmark import mpoly_all sage: mpoly_all() # not tested <BLANKLINE> ... ...System min avg max trials cpu or wall ... * sage...
""" systems = ['sage', 'magma', 'mathematica', 'macaulay2'] if include_maple: systems.append('maple') MPolynomialMult(200).run(systems=systems) MPolynomialMult(400).run(systems=systems) MPolynomialMult2(256).run(systems=systems) MPolynomialMult2(512).run(systems=systems) MPolynomialPower(nvars=4,exp=50).run(systems=systems) # mathematica wins MPolynomialPower(nvars=10,exp=10).run(systems=systems)
ModularSymbols1(2006,2) ModularSymbols1(1,50) ModularSymbols1(1,100) ModularSymbols1(1,150) ModularSymbols1(30,8) ModularSymbols1(225,4) ModularSymbols1(2,50) ModularSymbols1(2,100)
ModularSymbolsDecomp1(1,24).run() ModularSymbolsDecomp1(125,2).run() ModularSymbolsDecomp1(389,2).run() ModularSymbolsDecomp1(1,100).run() ModularSymbolsDecomp1(54,4).run()
EllipticCurveTraces(100000).run() EllipticCurveTraces(500000).run() Divpoly(59).run() EllipticCurvePointMul(1000).run() EllipticCurvePointMul(2000).run() EllipticCurvePointMul(2500).run() # sage is clearly using the wrong algorithm -- maybe need a balanced rep!?
# NOTE -- Sage can also do these using Simon's program, which is # *way* *way* faster than MAGMA... EllipticCurveMW([5,6,7,8,9]).run() EllipticCurveMW([50,6,7,8,9]).run() EllipticCurveMW([1, -1, 0, -79, 289]).run(trials=1) # rank 4 EllipticCurveMW([0, 0, 1, -79, 342]).run(trials=1) # rank 5 (Sage wins) |