Skip to content

Commit ee7dd30

Browse files
committed
Add SciPy template
1 parent da1440c commit ee7dd30

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env python
2+
"""Benchmark scipy.TODO.TODO."""
3+
4+
from __future__ import print_function
5+
import timeit
6+
7+
NAME = "TODO"
8+
REPEATS = 3
9+
ITERATIONS = 1000000
10+
11+
12+
def print_version():
13+
"""Print the TAP version."""
14+
print("TAP version 13")
15+
16+
17+
def print_summary(total, passing):
18+
"""Print the benchmark summary.
19+
20+
# Arguments
21+
22+
* `total`: total number of tests
23+
* `passing`: number of passing tests
24+
25+
"""
26+
print("#")
27+
print("1.." + str(total)) # TAP plan
28+
print("# total " + str(total))
29+
print("# pass " + str(passing))
30+
print("#")
31+
print("# ok")
32+
33+
34+
def print_results(elapsed):
35+
"""Print benchmark results.
36+
37+
# Arguments
38+
39+
* `elapsed`: elapsed time (in seconds)
40+
41+
# Examples
42+
43+
``` python
44+
python> print_results(0.131009101868)
45+
```
46+
"""
47+
rate = ITERATIONS / elapsed
48+
49+
print(" ---")
50+
print(" iterations: " + str(ITERATIONS))
51+
print(" elapsed: " + str(elapsed))
52+
print(" rate: " + str(rate))
53+
print(" ...")
54+
55+
56+
def benchmark():
57+
"""Run the benchmark and print benchmark results."""
58+
setup = "from scipy import TODO; from random import random;"
59+
stmt = "y = TODO(random())"
60+
61+
t = timeit.Timer(stmt, setup=setup)
62+
63+
print_version()
64+
65+
for i in xrange(REPEATS):
66+
print("# python::" + NAME)
67+
elapsed = t.timeit(number=ITERATIONS)
68+
print_results(elapsed)
69+
print("ok " + str(i+1) + " benchmark finished")
70+
71+
print_summary(REPEATS, REPEATS)
72+
73+
74+
def main():
75+
"""Run the benchmark."""
76+
benchmark()
77+
78+
79+
if __name__ == "__main__":
80+
main()

0 commit comments

Comments
 (0)