Example #1
0
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))
Example #2
0
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"))
Example #3
0
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"))
Example #4
0
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)
Example #5
0
    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()
Example #6
0
def mpf_from_mpz(value):
    return mpf(int(value))
Example #7
0
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)
Example #8
0
    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()

Example #9
0
def mpf_from_mpz(value):
    return mpf(int(value))