Make it compile with the Cython in Debian.
[sympyx.git] / benchmarks.py
blobed9b4020a9ae412501425b9ba1cbb39021aaeaaa
1 #!/usr/bin/env python
3 from timeit import default_timer as clock
4 from random import randint
5 try:
6 from sympy import Symbol, Add, Mul
7 print 'I: Running SymPy'
8 except ImportError:
9 from sympycore import Symbol
10 print 'I: Running sympycore'
12 x = Symbol("x")
13 y = Symbol("y")
14 z = Symbol("z")
17 def bench_e2e_1():
18 "e=(x+y+z+1)**10;f=e*(e+1);f.expand()"
19 e = (x+y+z+1)**10
20 f = e*(e+1)
21 f = f.expand()
23 def bench_e2e_2():
24 "e=(x+y+z+1)**10; f=e**2+e; f.expand()"
25 e = (x+y+z+1)**10
26 f = e**2 + e
27 f = f.expand()
29 def bench_e2e_3():
30 "e=(x+y+z+1)**20; f=e**2+e; f.expand()"
31 e = (x+y+z+1)**20
32 f = e**2 + e
33 f = f.expand()
35 def bench_e2e_4():
36 "e=(x+y+z+1)**30; f=e**2+e; f.expand()"
37 e = (x+y+z+1)**30
38 f = e**2 + e
39 f = f.expand()
41 def bench_e2e_5():
42 "e=(x+y+z+1)**40; f=e**2+e; f.expand()"
43 e = (x+y+z+1)**40
44 f = e**2 + e
45 f = f.expand()
47 def bench_expand1():
48 "e=(x+y+z+1)**10; e.expand()"
49 e = (x+y+z+1)**10
50 e = e.expand()
52 def bench_expand2():
53 "e=(x+y+z+1)**50; e.expand()"
54 e = (x+y+z+1)**50
55 e = e.expand()
57 def bench_expand3():
58 "e=(x+z+y)**20 * (z+x)**9; e.expand()"
59 e = (x+z+y)**20 * (z+x)**9
60 e = e.expand()
62 def bench_expand3():
63 "e=((x**x+y**y+z**z)**10 * (x**y+y**z+z**x)**10); e.expand()"
64 e = ((x**x+y**y+z**z)**10 * (x**y+y**z+z**x)**10)
65 e = e.expand()
67 def add1():
68 "Add(x,<random integer>,y), 2000x"
69 i = 2000
70 while i:
71 i -= 1
72 Add((x, randint(0, 1000000), y))
74 def mul1():
75 "Mul(x,<random integer>,y), 2000x"
76 i = 2000
77 while i:
78 i -= 1
79 Mul((x, randint(0, 1000000), y))
81 def sum1():
82 "sum(x**i/i,i=1..400)"
83 s = 0
84 i = 401
85 while i:
86 s += x**i/i
87 i -= 1
89 def sum2():
90 "sum(x**i/i,i=1..400), using Add(terms)"
91 terms = []
92 i = 401
93 while i:
94 terms.append(x**i/i)
95 i -= 1
96 s = Add(terms)
99 benchmarks = [
100 bench_e2e_1,
101 bench_e2e_2,
102 bench_e2e_3,
103 bench_e2e_4,
104 # too slow:
105 #bench_e2e_5,
106 bench_expand1,
107 bench_expand2,
108 bench_expand3,
109 add1,
110 mul1,
111 sum1,
112 sum2,
115 report = []
116 for b in benchmarks:
117 t = clock()
119 t = clock()-t
120 print "%65s: %f" % (b.__doc__, t)