-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathsimple_benchmarks.py
More file actions
183 lines (153 loc) · 4.29 KB
/
simple_benchmarks.py
File metadata and controls
183 lines (153 loc) · 4.29 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
"""Benchmarks for basic operations of a number of flint types.
These benchmarks are written using pyperf, and can be run by
python benchmarks/simple_benchmarks.py
Since each benchmark is very short ("microbenchmarks"), they may
require an increased number of samples to produce statistically
significant results (via the --values flag).
"""
import pyperf
from utils import get_all_benchmarks
NUM_EXECUTIONS = 10000000
def benchmark_arb_addition(runner: pyperf.Runner):
"""Simple benchmark for adding two arbs."""
runner.timeit(
name="arb addition",
setup=[
"from flint import arb",
"a = arb(1, 2)",
"b = arb.pi()",
],
stmt="a + b"
)
def benchmark_arb_multiplication(runner: pyperf.Runner):
"""Simple benchmark for multiplying two arbs."""
runner.timeit(
name="arb multiplication",
setup=[
"from flint import arb",
"a = arb(1, 2)",
"b = arb.pi()",
],
stmt="a * b"
)
def benchmark_arb_contains(runner: pyperf.Runner):
"""Simple benchmark for comparing two arbs."""
runner.timeit(
name="arb contains",
setup=[
"from flint import arb",
"a = arb(1, 2)",
"b = arb.pi()",
],
stmt=[
"a in b",
"b in a",
]
)
def benchmark_fmpz_addition(runner: pyperf.Runner):
"""Simple benchmark for adding two fmpzs."""
runner.timeit(
name="fmpz addition",
setup=[
"from flint import fmpz",
"a = fmpz(1)",
"b = fmpz(6)",
],
stmt="a + b"
)
def benchmark_fmpz_multiplication(runner: pyperf.Runner):
"""Simple benchmark for multiplying two fmpzs."""
runner.timeit(
name="fmpz multiplication",
setup=[
"from flint import fmpz",
"a = fmpz(1)",
"b = fmpz(6)",
],
stmt="a * b"
)
def benchmark_fmpz_eq(runner: pyperf.Runner):
"""Simple benchmark for equality on two fmpzs."""
runner.timeit(
name="fmpz equality",
setup=[
"from flint import fmpz",
"a = fmpz(1)",
"b = fmpz(6)",
],
stmt=["a == b", "b == a"]
)
def benchmark_fmpq_addition(runner: pyperf.Runner):
"""Simple benchmark for adding two fmpqs."""
runner.timeit(
name="fmpq addition",
setup=[
"from flint import fmpq",
"a = fmpq(1, 2)",
"b = fmpq(15, 7)",
],
stmt="a + b"
)
def benchmark_fmpq_multiplication(runner: pyperf.Runner):
"""Simple benchmark for multiplying two fmpqs."""
runner.timeit(
name="fmpq multiplication",
setup=[
"from flint import fmpq",
"a = fmpq(1, 2)",
"b = fmpq(15, 7)",
],
stmt="a * b"
)
def benchmark_fmpq_eq(runner: pyperf.Runner):
"""Simple benchmark for equality on two fmpqs."""
runner.timeit(
name="fmpq equality",
setup=[
"from flint import fmpq",
"a = fmpq(1, 2)",
"b = fmpq(15, 7)",
],
stmt=["a == b", "b == a"]
)
def benchmark_acb_addition(runner: pyperf.Runner):
"""Simple benchmark for adding two acbs."""
runner.timeit(
name="acb addition",
setup=[
"from flint import acb",
"a = acb(1 + 3j)",
"b = acb.pi()",
],
stmt="a + b"
)
def benchmark_acb_multiplication(runner: pyperf.Runner):
"""Simple benchmark for multiplying two acbs."""
runner.timeit(
name="acb multiplication",
setup=[
"from flint import acb",
"a = acb(1 + 3j)",
"b = acb.pi()",
],
stmt="a * b"
)
def benchmark_acb_eq(runner: pyperf.Runner):
"""Simple benchmark for containment on two acbs."""
runner.timeit(
name="acb contains",
setup=[
"from flint import acb",
"a = acb(1 + 3j)",
"b = acb.pi()",
],
stmt=["a in b", "b in a"]
)
def main():
"""Run all the benchmarks."""
runner = pyperf.Runner()
benchmarks = get_all_benchmarks(__name__)
for benchmark in benchmarks:
benchmark(runner)
if __name__ == "__main__":
main()