1717import random
1818
1919import numpy
20+ import pytest
2021
2122import diffpy .srfit .equation .literals as literals
2223import diffpy .srfit .equation .visitors as visitors
2324
25+ pytestmark = pytest .mark .skip (
26+ reason = (
27+ "This is a performance benchmark test, "
28+ "not a unit test. Comment out this line "
29+ "to run performance testing."
30+ )
31+ )
32+
2433x = numpy .arange (0 , 20 , 0.05 )
2534
2635
27- def makeLazyEquation (make_args ):
36+ def make_lazy_equation (make_args ):
2837 """Make a lazy equation and see how fast it is."""
2938
3039 # Make some variables
@@ -72,7 +81,7 @@ def _f(a, b, c, d, e):
7281 return _f
7382
7483
75- def makeEquation1 ():
84+ def make_equation1 ():
7685 """Make the same equation as the lazy one."""
7786
7887 y = 50 * x
@@ -83,7 +92,7 @@ def _f(a, b, c, d, e):
8392 return _f
8493
8594
86- def timeFunction (f , * args , ** kw ):
95+ def time_function (f , * args , ** kw ):
8796 """Time a function in ms."""
8897 import time
8998
@@ -93,9 +102,9 @@ def timeFunction(f, *args, **kw):
93102 return (t2 - t1 ) * 1000
94103
95104
96- def speedTest1 ():
97- f1 = makeLazyEquation ()
98- f2 = makeEquation1 ()
105+ def test_speed1 ():
106+ f1 = make_lazy_equation ()
107+ f2 = make_equation1 ()
99108
100109 args = [3.1 , 8.19973123410 , 2.1 , numpy .e , numpy .pi ]
101110
@@ -104,8 +113,8 @@ def speedTest1():
104113 for i in range (len (args )):
105114 args [i ] = 10 * random .random ()
106115 print ("Changing argument %i" % (i + 1 ))
107- t1 = timeFunction (f1 , * args )
108- t2 = timeFunction (f2 , * args )
116+ t1 = time_function (f1 , * args )
117+ t2 = time_function (f2 , * args )
109118 total1 += t1
110119 total2 += t2
111120 print ("lazy" , t1 )
@@ -117,7 +126,7 @@ def speedTest1():
117126 print ("Ratio (lazy/regular)" , total1 / total2 )
118127
119128
120- def speedTest2 (mutate = 2 ):
129+ def test_speed2 (mutate = 2 ):
121130
122131 from diffpy .srfit .equation .builder import EquationFactory
123132
@@ -176,8 +185,8 @@ def f(A0, qsig, sigma1, sigma2, b1, b2, b3, b4, b5, b6, b7, b8):
176185 args [idx ] = random .random ()
177186
178187 # Time the different functions with these arguments
179- tnpy += timeFunction (f , * args )
180- teq += timeFunction (eq , * args )
188+ tnpy += time_function (f , * args )
189+ teq += time_function (eq , * args )
181190
182191 print (
183192 "Average call time (%i calls, %i mutations/call):" % (numcalls , mutate )
@@ -189,7 +198,7 @@ def f(A0, qsig, sigma1, sigma2, b1, b2, b3, b4, b5, b6, b7, b8):
189198 return
190199
191200
192- def speedTest3 (mutate = 2 ):
201+ def test_speed3 (mutate = 2 ):
193202 """Test wrt sympy.
194203
195204 Results - sympy is 10 to 24 times faster without using arrays (ouch!).
@@ -265,8 +274,8 @@ def speedTest3(mutate=2):
265274 args [idx ] = random .random ()
266275
267276 # Time the different functions with these arguments
268- teq += timeFunction (eq , * (args [:- 1 ]))
269- tnpy += timeFunction (f , * args )
277+ teq += time_function (eq , * (args [:- 1 ]))
278+ tnpy += time_function (f , * args )
270279
271280 print (
272281 "Average call time (%i calls, %i mutations/call):" % (numcalls , mutate )
@@ -278,7 +287,7 @@ def speedTest3(mutate=2):
278287 return
279288
280289
281- def speedTest4 (mutate = 2 ):
290+ def test_speed4 (mutate = 2 ):
282291 """Test wrt sympy.
283292
284293 Results - sympy is 10 to 24 times faster without using arrays (ouch!).
@@ -310,7 +319,7 @@ def speedTest4(mutate=2):
310319 teq = 0
311320 # Randomly change variables
312321 numargs = len (eq .args )
313- choices = range (numargs )
322+ choices = list ( range (numargs ) )
314323 args = [1.0 ] * (len (eq .args ))
315324 args .append (x )
316325
@@ -329,8 +338,8 @@ def speedTest4(mutate=2):
329338 args [idx ] = random .random ()
330339
331340 # Time the different functions with these arguments
332- teq += timeFunction (eq , * (args [:- 1 ]))
333- tnpy += timeFunction (f , * args )
341+ teq += time_function (eq , * (args [:- 1 ]))
342+ tnpy += time_function (f , * args )
334343
335344 print (
336345 "Average call time (%i calls, %i mutations/call):" % (numcalls , mutate )
@@ -342,7 +351,7 @@ def speedTest4(mutate=2):
342351 return
343352
344353
345- def weightedTest (mutate = 2 ):
354+ def test_weighted (mutate = 2 ):
346355 """Show the benefits of a properly balanced equation tree."""
347356
348357 from diffpy .srfit .equation .builder import EquationFactory
@@ -379,7 +388,7 @@ def f(b1, b2, b3, b4, b5, b6, b7, b8):
379388 teq = 0
380389 # Randomly change variables
381390 numargs = len (eq .args )
382- choices = range (numargs )
391+ choices = list ( range (numargs ) )
383392 args = [0.1 ] * numargs
384393
385394 # The call-loop
@@ -399,8 +408,8 @@ def f(b1, b2, b3, b4, b5, b6, b7, b8):
399408 # print(args)
400409
401410 # Time the different functions with these arguments
402- teq += timeFunction (eq , * args )
403- tnpy += timeFunction (f , * args )
411+ teq += time_function (eq , * args )
412+ tnpy += time_function (f , * args )
404413
405414 print (
406415 "Average call time (%i calls, %i mutations/call):" % (numcalls , mutate )
@@ -412,9 +421,9 @@ def f(b1, b2, b3, b4, b5, b6, b7, b8):
412421 return
413422
414423
415- def profileTest ():
424+ def test_profile ():
416425
417- from diffpy .srfit .builder import EquationFactory
426+ from diffpy .srfit .equation . builder import EquationFactory
418427
419428 factory = EquationFactory ()
420429
@@ -437,7 +446,7 @@ def profileTest():
437446
438447 mutate = 8
439448 numargs = len (eq .args )
440- choices = range (numargs )
449+ choices = list ( range (numargs ) )
441450 args = [0.1 ] * numargs
442451
443452 # The call-loop
0 commit comments