def test(n=100*1000): print("Sum of %d items of various types:" % n) for z in 0, 0.0, gmpy.mpz(0), gmpy.mpf(0): tip, tim, tot = timedsum(n, z) print(" %5.3f %.0f %s" % (tim, float(tot), tip)) print("Sum of %d items of various types w/2.3 sum builtin:" % n) for z in 0, 0.0, gmpy.mpz(0), gmpy.mpf(0): tip, tim, tot = timedsum1(n, z) print(" %5.3f %.0f %s" % (tim, float(tot), tip)) print("Mul of %d items of various types:" % (n//5)) for z in 1, 1.0, gmpy.mpz(1), gmpy.mpf(1): tip, tim, tot = timedmul(n//5, z) print(" %5.3f %s" % (tim, tip))
def test(n=100 * 1000): print("%dth Fibonacci number of various types:" % n) for z in 0, gmpy.mpz(0), gmpy.mpf(0): tip, tim, tot = timedfib(n, z) print(" %5.3f %s %s" % (tim, gmpy.fdigits(tot, 10, 6), tip)) tip, tim, tot = timedfibsp(n, 1) print(" %5.3f %s %s" % (tim, gmpy.fdigits(tot, 10, 6), "gmpy.fib"))
def test(n=100*1000): print("%dth Fibonacci number of various types:" % n) for z in 0, gmpy.mpz(0), gmpy.mpf(0): tip, tim, tot = timedfib(n, z) print(" %5.3f %s %s" % (tim, gmpy.fdigits(tot,10,6), tip)) tip, tim, tot = timedfibsp(n, 1) print(" %5.3f %s %s" % (tim, gmpy.fdigits(tot,10,6), "gmpy.fib"))
def test(n=100 * 1000): print "Sum of %d items of various types:" % n for z in 0L, 0.0, gmpy.mpz(0), gmpy.mpf(0): tip, tim, tot = timedsum(n, z) print " %5.3f %.0f %s" % (tim, float(tot), tip)
stend = time.clock() return type(zero), stend - start, tot def timedmul(n, one): start = time.clock() tot = one for i in range(n): tot *= (i + 1) stend = time.clock() return type(one), stend - start, tot def test(n=100 * 1000): print "Sum of %d items of various types:" % n for z in 0L, 0.0, gmpy.mpz(0), gmpy.mpf(0): tip, tim, tot = timedsum(n, z) print " %5.3f %.0f %s" % (tim, float(tot), tip) print "Sum of %d items of various types w/2.3 sum builtin:" % n for z in 0L, 0.0, gmpy.mpz(0), gmpy.mpf(0): tip, tim, tot = timedsum1(n, z) print " %5.3f %.0f %s" % (tim, float(tot), tip) print "Mul of %d items of various types:" % (n // 5) for z in 1L, 1.0, gmpy.mpz(1), gmpy.mpf(1): tip, tim, tot = timedmul(n // 5, z) print " %5.3f %s" % (tim, tip) if __name__ == '__main__': test()
def mpf_from_mpz(value): return mpf(int(value))
def test(n=100*1000): print "Sum of %d items of various types:" % n for z in 0L, 0.0, gmpy.mpz(0), gmpy.mpf(0): tip, tim, tot = timedsum(n, z) print " %5.3f %.0f %s" % (tim, float(tot), tip)
tot=sum(range(n), zero) stend=time.clock() return type(zero), stend-start, tot def timedmul(n, one): start=time.clock() tot=one for i in range(n): tot*=(i+1) stend=time.clock() return type(one), stend-start, tot def test(n=100*1000): print "Sum of %d items of various types:" % n for z in 0L, 0.0, gmpy.mpz(0), gmpy.mpf(0): tip, tim, tot = timedsum(n, z) print " %5.3f %.0f %s" % (tim, float(tot), tip) print "Sum of %d items of various types w/2.3 sum builtin:" % n for z in 0L, 0.0, gmpy.mpz(0), gmpy.mpf(0): tip, tim, tot = timedsum1(n, z) print " %5.3f %.0f %s" % (tim, float(tot), tip) print "Mul of %d items of various types:" % (n//5) for z in 1L, 1.0, gmpy.mpz(1), gmpy.mpf(1): tip, tim, tot = timedmul(n//5, z) print " %5.3f %s" % (tim, tip) if __name__=='__main__': test()