-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmarks.py
executable file
·60 lines (48 loc) · 1.11 KB
/
benchmarks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
from timeit import default_timer as clock
from random import randint
from pycsympy.basic import Symbol
from pycsympy.multinomial import multinomial_coefficients
x = Symbol("x")
y = Symbol("y")
z = Symbol("z")
w = Symbol("w")
def bench_expand1():
"e=(x+y+z+w)**60; e.expand()"
e = (x+y+z+w)**60
return e.expand()
def _expand1():
"""multinomial_coefficients(4, 60)"""
return multinomial_coefficients(4, 60)
def bench_expand2():
"e=(x+y+z+1)**50; e.expand()"
e = (x+y+z+1)**50
e = e.expand()
def expand3():
"""(x**y + y**z + z**x)**100"""
e = (x**y + y**z + z**x)**100
return e.expand()
def add1():
"Add(x,<random integer>,y), 2000x"
for i in range(2000):
x + randint(0, 1000000) + y
def sum1():
s = 0
for i in range(401):
s += x**i
benchmarks = [
bench_expand1,
_expand1,
bench_expand2,
expand3,
add1,
sum1,
]
report = []
for b in benchmarks:
for _ in range(10):
t = clock()
b()
t = clock()-t
print "%65s: %f" % (b.__doc__, t)
print