CoCalc Public Fileswww / talks / pyrex / misc / prof.pyOpen with one click!
Author: William A. Stein
1
import timeit
2
3
def matmul(tries=10, p=97, n=20):
4
T0 = timeit.Timer("a=mult1.Matrix(%s,%s,range(%s*%s)); a*a"%\
5
(p,n,n,n), "import mult1")
6
T1 = timeit.Timer("a=mult2.Matrix(%s,%s,range(%s*%s)); a*a"%\
7
(p,n,n,n), "import mult2")
8
T2 = timeit.Timer("a=mult3.Matrix(%s,%s,range(%s*%s)); a*a"%\
9
(p,n,n,n), "import mult3")
10
t0 = T0.timeit(tries)
11
t1 = T1.timeit(tries)
12
t2 = T2.timeit(tries)
13
print "Pure Python: %s\nPyrex: %s (Speedup: %s)"%(t0, t1, t0/t1)
14
print "Psyco: %s (Speedup: %s)"%(t2, t0/t2)
15
16