2424# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
2525# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626# *****************************************************************************
27- import string
27+
2828import time
2929
30- import numba
3130import pandas
3231import numpy as np
3332
3433from sdc .tests .test_utils import test_global_input_data_float64
3534from sdc .tests .tests_perf .test_perf_base import TestBase
36- from sdc .tests .tests_perf .test_perf_utils import (calc_compilation , get_times ,
37- perf_data_gen_fixed_len )
35+ from sdc .tests .tests_perf .test_perf_utils import perf_data_gen_fixed_len
3836from .generator import generate_test_cases
3937from .generator import TestCase as TC
4038
4139
40+ rolling_usecase_tmpl = """
41+ def series_rolling_{method_name}_usecase(data, {extra_usecase_params}):
42+ start_time = time.time()
43+ for i in range({ncalls}):
44+ res = data.rolling({rolling_params}).{method_name}({method_params})
45+ end_time = time.time()
46+ return end_time - start_time, res
47+ """
48+
49+
4250def get_rolling_params (window = 100 , min_periods = None ):
4351 """Generate supported rolling parameters"""
4452 rolling_params = [f'{ window } ' ]
@@ -48,14 +56,37 @@ def get_rolling_params(window=100, min_periods=None):
4856 return ', ' .join (rolling_params )
4957
5058
59+ def gen_series_rolling_usecase (method_name , rolling_params = None ,
60+ extra_usecase_params = '' ,
61+ method_params = '' , ncalls = 1 ):
62+ """Generate series rolling method use case"""
63+ if not rolling_params :
64+ rolling_params = get_rolling_params ()
65+
66+ func_text = rolling_usecase_tmpl .format (** {
67+ 'method_name' : method_name ,
68+ 'extra_usecase_params' : extra_usecase_params ,
69+ 'rolling_params' : rolling_params ,
70+ 'method_params' : method_params ,
71+ 'ncalls' : ncalls
72+ })
73+
74+ global_vars = {'np' : np , 'time' : time }
75+ loc_vars = {}
76+ exec (func_text , global_vars , loc_vars )
77+ _series_rolling_usecase = loc_vars [f'series_rolling_{ method_name } _usecase' ]
78+
79+ return _series_rolling_usecase
80+
81+
5182# python -m sdc.runtests sdc.tests.tests_perf.test_perf_series_rolling.TestSeriesRollingMethods
5283class TestSeriesRollingMethods (TestBase ):
53- # more than 19 columns raise SystemError: CPUDispatcher() returned a result with an error set
54- max_columns_num = 19
55-
5684 @classmethod
5785 def setUpClass (cls ):
5886 super ().setUpClass ()
87+ cls .map_ncalls_dlength = {
88+ 'sum' : (100 , [8 * 10 ** 5 ]),
89+ }
5990
6091 def _test_case (self , pyfunc , name , total_data_length , data_num = 1 ,
6192 input_data = test_global_input_data_float64 ):
@@ -82,6 +113,20 @@ def _test_case(self, pyfunc, name, total_data_length, data_num=1,
82113 self ._test_jit (pyfunc , base , * args )
83114 self ._test_py (pyfunc , base , * args )
84115
116+ def _test_series_rolling_method (self , name , rolling_params = None ,
117+ extra_usecase_params = '' , method_params = '' ):
118+ ncalls , total_data_length = self .map_ncalls_dlength [name ]
119+ usecase = gen_series_rolling_usecase (name , rolling_params = rolling_params ,
120+ extra_usecase_params = extra_usecase_params ,
121+ method_params = method_params , ncalls = ncalls )
122+ data_num = 1
123+ if extra_usecase_params :
124+ data_num += len (extra_usecase_params .split (', ' ))
125+ self ._test_case (usecase , name , total_data_length , data_num = data_num )
126+
127+ def test_series_rolling_sum (self ):
128+ self ._test_series_rolling_method ('sum' )
129+
85130
86131cases = [
87132 TC (name = 'apply' , size = [10 ** 7 ], params = 'func=lambda x: np.nan if len(x) == 0 else x.mean()' ),
@@ -96,7 +141,6 @@ def _test_case(self, pyfunc, name, total_data_length, data_num=1,
96141 TC (name = 'quantile' , size = [10 ** 7 ], params = '0.2' ),
97142 TC (name = 'skew' , size = [10 ** 7 ]),
98143 TC (name = 'std' , size = [10 ** 7 ]),
99- TC (name = 'sum' , size = [10 ** 7 ]),
100144 TC (name = 'var' , size = [10 ** 7 ]),
101145]
102146
0 commit comments