11#!/usr/bin/env python
22"""Benchmark scipy.stats.gamma."""
33
4+ from __future__ import print_function
45import timeit
56
6- repeats = 3
7- count = [0 ] # use a list to allow modification within nested scopes
7+ REPEATS = 3
8+ COUNT = [0 ] # use a list to allow modification within nested scopes
89
910
1011def print_version ():
1112 """Print the TAP version."""
12-
1313 print ("TAP version 13" )
1414
1515
@@ -22,7 +22,6 @@ def print_summary(total, passing):
2222 * `passing`: number of passing tests
2323
2424 """
25-
2625 print ("#" )
2726 print ("1.." + str (total )) # TAP plan
2827 print ("# total " + str (total ))
@@ -45,7 +44,6 @@ def print_results(iterations, elapsed):
4544 python> print_results(1000000, 0.131009101868)
4645 ```
4746 """
48-
4947 rate = iterations / elapsed
5048
5149 print (" ---" )
@@ -71,22 +69,22 @@ def benchmark(name, setup, stmt, iterations):
7169 python> benchmark("random", "from random import random;", "y = random()", 1000000)
7270 ```
7371 """
74-
7572 t = timeit .Timer (stmt , setup = setup )
7673
7774 print_version ()
7875
79- for i in xrange (repeats ):
76+ i = 0
77+ while i < REPEATS :
8078 print ("# python::" + name )
81- count [0 ] += 1
79+ COUNT [0 ] += 1
8280 elapsed = t .timeit (number = iterations )
8381 print_results (iterations , elapsed )
84- print ("ok " + str (count [0 ]) + " benchmark finished" )
82+ print ("ok " + str (COUNT [0 ]) + " benchmark finished" )
83+ i += 1
8584
8685
8786def main ():
8887 """Run the benchmarks."""
89-
9088 name = "gamma:entropy"
9189 setup = "from scipy.stats import gamma; from random import random; rv = gamma(100.56789, 55.54321);"
9290 stmt = "y = rv.entropy()"
@@ -147,7 +145,7 @@ def main():
147145 iterations = 1000
148146 benchmark (name , setup , stmt , iterations )
149147
150- print_summary (count [0 ], count [0 ])
148+ print_summary (COUNT [0 ], COUNT [0 ])
151149
152150
153151if __name__ == "__main__" :
0 commit comments