Skip to content

Commit 224c819

Browse files
committed
"added benchmark.py"
1 parent c0ba73e commit 224c819

File tree

1 file changed

+97
-0
lines changed
  • lib/node_modules/@stdlib/math/base/special/cosc/benchmark/scipy

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env python
2+
#
3+
# @license Apache-2.0
4+
#
5+
# Copyright (c) 2018 The Stdlib Authors.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
"""Benchmark scipy.special.cosc."""
20+
21+
from __future__ import print_function
22+
import timeit
23+
24+
NAME = "cosc"
25+
REPEATS = 3
26+
ITERATIONS = 100000
27+
28+
29+
def print_version():
30+
"""Print the TAP version."""
31+
print("TAP version 13")
32+
33+
34+
def print_summary(total, passing):
35+
"""Print the benchmark summary.
36+
37+
# Arguments
38+
39+
* `total`: total number of tests
40+
* `passing`: number of passing tests
41+
42+
"""
43+
print("#")
44+
print("1.." + str(total)) # TAP plan
45+
print("# total " + str(total))
46+
print("# pass " + str(passing))
47+
print("#")
48+
print("# ok")
49+
50+
51+
def print_results(elapsed):
52+
"""Print benchmark results.
53+
54+
# Arguments
55+
56+
* `elapsed`: elapsed time (in seconds)
57+
58+
# Examples
59+
60+
``` python
61+
python> print_results(0.131009101868)
62+
```
63+
"""
64+
rate = ITERATIONS / elapsed
65+
66+
print(" ---")
67+
print(" iterations: " + str(ITERATIONS))
68+
print(" elapsed: " + str(elapsed))
69+
print(" rate: " + str(rate))
70+
print(" ...")
71+
72+
73+
def benchmark():
74+
"""Run the benchmark and print benchmark results."""
75+
setup = "from scipy.special import cosc; from random import random;"
76+
stmt = "y = cosc(2.0*random() - 2.0)"
77+
78+
t = timeit.Timer(stmt, setup=setup)
79+
80+
print_version()
81+
82+
for i in range(REPEATS):
83+
print("# python::scipy::" + NAME)
84+
elapsed = t.timeit(number=ITERATIONS)
85+
print_results(elapsed)
86+
print("ok " + str(i+1) + " benchmark finished")
87+
88+
print_summary(REPEATS, REPEATS)
89+
90+
91+
def main():
92+
"""Run the benchmark."""
93+
benchmark()
94+
95+
96+
if __name__ == "__main__":
97+
main()

0 commit comments

Comments
 (0)