Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit 7cc8733

Browse files
kozlov-alexeyshssf
authored andcommitted
Adding performance test for Series (A+B).sum() (#337)
1 parent e3f53bc commit 7cc8733

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

sdc/tests/tests_perf/test_perf_series.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
# *****************************************************************************
2727
import pandas as pd
28+
import numpy as np
2829

2930
from sdc.tests.test_utils import *
3031
from sdc.tests.tests_perf.test_perf_base import *
@@ -215,6 +216,15 @@ def usecase_series_dropna(input_data):
215216
return finish_time - start_time, res
216217

217218

219+
def usecase_series_chain_add_and_sum(A, B):
220+
start_time = time.time()
221+
res = (A + B).sum()
222+
finish_time = time.time()
223+
res_time = finish_time - start_time
224+
225+
return res_time, res
226+
227+
218228
# python -m sdc.runtests sdc.tests.tests_perf.test_perf_series.TestSeriesMethods
219229
class TestSeriesMethods(TestBase):
220230
@classmethod
@@ -243,7 +253,8 @@ def setUpClass(cls):
243253
'series_median': [10 ** 8],
244254
'series_argsort': [10 ** 5],
245255
'series_sort_values': [10 ** 5],
246-
'series_dropna': [2 * 10 ** 8]
256+
'series_dropna': [2 * 10 ** 8],
257+
'series_chain_add_and_sum': [20 * 10 ** 7, 25 * 10 ** 7, 30 * 10 ** 7],
247258
}
248259

249260
def _test_series(self, pyfunc, name, input_data=None):
@@ -265,6 +276,28 @@ def _test_series(self, pyfunc, name, input_data=None):
265276
exec_times, _ = get_times(pyfunc, test_data, iter_number=self.iter_number)
266277
self.test_results.add(name, 'Reference', test_data.size, test_results=exec_times)
267278

279+
def _test_series_binary_operations(self, pyfunc, name, input_data=None):
280+
np.random.seed(0)
281+
hpat_func = sdc.jit(pyfunc)
282+
for data_length in self.total_data_length[name]:
283+
284+
# TODO: replace with generic function to generate random sequence of floats
285+
data1 = np.random.ranf(data_length)
286+
data2 = np.random.ranf(data_length)
287+
A = pd.Series(data1)
288+
B = pd.Series(data2)
289+
290+
compile_results = calc_compilation(pyfunc, A, B, iter_number=self.iter_number)
291+
292+
# Warming up
293+
hpat_func(A, B)
294+
295+
exec_times, boxing_times = get_times(hpat_func, A, B, iter_number=self.iter_number)
296+
self.test_results.add(name, 'JIT', A.size, exec_times, boxing_times,
297+
compile_results=compile_results, num_threads=self.num_threads)
298+
exec_times, _ = get_times(pyfunc, A, B, iter_number=self.iter_number)
299+
self.test_results.add(name, 'Reference', A.size, exec_times, num_threads=self.num_threads)
300+
268301
def test_series_float_min(self):
269302
self._test_series(usecase_series_min, 'series_min')
270303

@@ -333,3 +366,6 @@ def test_series_float_sort_values(self):
333366

334367
def test_series_float_dropna(self):
335368
self._test_series(usecase_series_dropna, 'series_dropna')
369+
370+
def test_series_chain_add_and_sum(self):
371+
self._test_series_binary_operations(usecase_series_chain_add_and_sum, 'series_chain_add_and_sum')

0 commit comments

Comments
 (0)