@@ -0,0 +1,1837 @@
+import sys%0Aimport time%0A%0Afrom pypoly import *%0A%0Asparse_polynomial1 = Polynomial(0, 0, -3, 0, 0, 1, 0, 0, 0, 0, 0, 0, 5)%0Asparse_polynomial2 = sparse_polynomial1 * X**2 + 1%0A%0Adense_polynomial1 = Polynomial(1, -8, -3, 2, 5, 1, -1, 9, 8, 2, 3, 4, 5)%0Adense_polynomial2 = dense_polynomial1 * X**2 + 1%0A%0Adef add_sparse():%0A    sparse_polynomial1 + sparse_polynomial2%0A%0Adef mult_sparse():%0A    sparse_polynomial1 * sparse_polynomial2%0A%0Adef power_sparse():%0A    sparse_polynomial1**3%0A    sparse_polynomial2**4%0A%0Adef modulo_sparse():%0A    divmod(sparse_polynomial2, sparse_polynomial1)%0A%0Adef add_dense():%0A    dense_polynomial1 + dense_polynomial2%0A%0Adef mult_dense():%0A    dense_polynomial1 * dense_polynomial2%0A%0Adef power_dense():%0A    dense_polynomial1**3%0A    dense_polynomial2**4%0A%0Adef modulo_dense():%0A    divmod(dense_polynomial2, dense_polynomial1)%0A%0Adef X_op():%0A    1 + X + X**2 + X**3 + X**4 + X**5 + X**6%0A%0ABENCHMARK = (%0A        (add_sparse, 10**7),%0A        (mult_sparse, 2 * 10**6),%0A        (power_sparse, 2 * 10**5),%0A        (modulo_sparse, 2 * 10**6),%0A        (add_dense, 10**7),%0A        (mult_dense, 2 * 10**6),%0A        (power_dense, 2 * 10**5),%0A        (modulo_dense, 2 * 10**6),%0A        (X_op, 10**6),%0A    )%0A%0Adef bench_func(func, times=None):%0A    if times is None:%0A        times = 10**6%0A    step = times // 100%0A    print(%22%5B Calling %5C%22%25s%5C%22 %25g times%5D%22 %25 (func.__name__, times))%0A    before = time.time()%0A    for i in range(times):%0A        func()%0A        if i %25 step == 0:%0A            sys.stdout.write(%22.%22)%0A            sys.stdout.flush()%0A    after = time.time()%0A    elapsed = after - before%0A    print(%22%5Cn==%3E Done in %25ss (average %25ss)%5Cn%22 %25 (elapsed, elapsed / times))%0A    return elapsed%0A%0Adef run():%0A    total = 0%0A    for func, times in BENCHMARK:%0A        total += bench_func(func, times)%0A    print(%22Total: %25ss%22 %25 total)%0A%0Aif __name__ == '__main__':%0A    run()%0A

Add module benchmark