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

Commit 9bae742

Browse files
authored
Merge pull request #314 from Rubtsowa/testperf
performance tests for series.min/max
2 parents c7c5e65 + 3ca4d5a commit 9bae742

6 files changed

Lines changed: 237 additions & 97 deletions

File tree

sdc/tests/test_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
# *****************************************************************************
2727

28+
import numpy as np
2829

2930
import sdc
3031
import numba
@@ -36,6 +37,14 @@
3637
'大处 着眼,c小处着手c。大大c大处',
3738
]
3839

40+
min_float64 = np.finfo('float64').min
41+
max_float64 = np.finfo('float64').max
42+
43+
test_global_input_data_float64 = [
44+
[1., np.nan, -1., 0., min_float64, max_float64, max_float64, min_float64],
45+
[np.nan, np.inf, np.inf, np.nan, np.nan, np.nan, np.NINF, np.NZERO]
46+
]
47+
3948

4049
def count_array_REPs():
4150
if sdc.config.config_pipeline_hpat_default:

sdc/tests/tests_perf/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from sdc.tests.tests_perf.test_perf_unicode import *
22
from sdc.tests.tests_perf.test_perf_series_str import *
3+
from sdc.tests.tests_perf.test_perf_series import *
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# -*- coding: utf-8 -*-
2+
# *****************************************************************************
3+
# Copyright (c) 2019, Intel Corporation All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
#
8+
# Redistributions of source code must retain the above copyright notice,
9+
# this list of conditions and the following disclaimer.
10+
#
11+
# Redistributions in binary form must reproduce the above copyright notice,
12+
# this list of conditions and the following disclaimer in the documentation
13+
# and/or other materials provided with the distribution.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
19+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
# *****************************************************************************
27+
import pandas as pd
28+
29+
from sdc.tests.test_utils import *
30+
from sdc.tests.tests_perf.test_perf_base import TestBase
31+
from sdc.tests.tests_perf.test_perf_utils import *
32+
33+
34+
def usecase_series_min(input_data):
35+
start_time = time.time()
36+
res = input_data.min()
37+
finish_time = time.time()
38+
39+
return finish_time - start_time, res
40+
41+
42+
def usecase_series_max(input_data):
43+
start_time = time.time()
44+
res = input_data.max()
45+
finish_time = time.time()
46+
47+
return finish_time - start_time, res
48+
49+
50+
# python -m sdc.runtests sdc.tests.tests_perf.test_perf_series.TestSeriesMethods
51+
class TestSeriesMethods(TestBase):
52+
@classmethod
53+
def setUpClass(cls):
54+
super().setUpClass()
55+
cls.total_data_length = [5 * 10 ** 8]
56+
57+
def _test_series(self, pyfunc, name):
58+
input_data = test_global_input_data_float64
59+
hpat_func = sdc.jit(pyfunc)
60+
for data_length in self.total_data_length:
61+
data, = perf_data_gen_fixed_len(input_data, data_length, 1)
62+
test_data = pd.Series(data)
63+
64+
compile_results = calc_compilation(pyfunc, test_data, iter_number=self.iter_number)
65+
# Warming up
66+
hpat_func(test_data)
67+
68+
exec_times, boxing_times = get_times(hpat_func, test_data, iter_number=self.iter_number)
69+
self.test_results.add(name, 'JIT', test_data.size, exec_times, boxing_results=boxing_times,
70+
compile_results=compile_results)
71+
72+
exec_times, _ = get_times(pyfunc, test_data, iter_number=self.iter_number)
73+
self.test_results.add(name, 'Reference', test_data.size, test_results=exec_times)
74+
75+
def test_series_float_min(self):
76+
self._test_series(usecase_series_min, 'series_float_min')
77+
78+
def test_series_float_max(self):
79+
self._test_series(usecase_series_max, 'series_float_max')

sdc/tests/tests_perf/test_perf_series_str.py

Lines changed: 33 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -26,145 +26,107 @@
2626
# *****************************************************************************
2727

2828
import itertools
29+
import os
2930
import time
3031
import unittest
3132
from contextlib import contextmanager
3233

3334
import pandas as pd
3435

3536
from sdc.tests.test_utils import *
36-
from sdc.tests.tests_perf.test_perf_base import TestBase
3737
from sdc.tests.tests_perf.test_perf_utils import *
3838

3939

4040
def usecase_series_len(input_data):
4141
start_time = time.time()
42-
input_data.str.len()
42+
res = input_data.str.len()
4343
finish_time = time.time()
4444

45-
return finish_time - start_time
45+
return finish_time - start_time, res
4646

4747

4848
def usecase_series_capitalize(input_data):
4949
start_time = time.time()
50-
input_data.str.capitalize()
50+
res = input_data.str.capitalize()
5151
finish_time = time.time()
5252

53-
return finish_time - start_time
53+
return finish_time - start_time, res
5454

5555

5656
def usecase_series_lower(input_data):
5757
start_time = time.time()
58-
input_data.str.lower()
58+
res = input_data.str.lower()
5959
finish_time = time.time()
6060

61-
return finish_time - start_time
61+
return finish_time - start_time, res
6262

6363

6464
def usecase_series_swapcase(input_data):
6565
start_time = time.time()
66-
input_data.str.swapcase()
66+
res = input_data.str.swapcase()
6767
finish_time = time.time()
6868

69-
return finish_time - start_time
69+
return finish_time - start_time, res
7070

7171

7272
def usecase_series_title(input_data):
7373
start_time = time.time()
74-
input_data.str.title()
74+
res = input_data.str.title()
7575
finish_time = time.time()
7676

77-
return finish_time - start_time
77+
return finish_time - start_time, res
7878

7979

8080
def usecase_series_upper(input_data):
8181
start_time = time.time()
82-
input_data.str.upper()
82+
res = input_data.str.upper()
8383
finish_time = time.time()
8484

85-
return finish_time - start_time
85+
return finish_time - start_time, res
8686

8787

8888
def usecase_series_lstrip(input_data):
8989
start_time = time.time()
90-
input_data.str.lstrip()
90+
res = input_data.str.lstrip()
9191
finish_time = time.time()
9292

93-
return finish_time - start_time
93+
return finish_time - start_time, res
9494

9595

9696
def usecase_series_rstrip(input_data):
9797
start_time = time.time()
98-
input_data.str.rstrip()
98+
res = input_data.str.rstrip()
9999
finish_time = time.time()
100100

101-
return finish_time - start_time
101+
return finish_time - start_time, res
102102

103103

104104
def usecase_series_strip(input_data):
105105
start_time = time.time()
106-
input_data.str.strip()
106+
res = input_data.str.strip()
107107
finish_time = time.time()
108108

109-
return finish_time - start_time
109+
return finish_time - start_time, res
110110

111111

112-
@contextmanager
113-
def do_jit(f):
114-
"""Context manager to jit function"""
115-
cfunc = sdc.jit(f)
116-
try:
117-
yield cfunc
118-
finally:
119-
del cfunc
112+
class TestSeriesStringMethods(unittest.TestCase):
113+
iter_number = 5
120114

121-
122-
def calc_time(func, *args, **kwargs):
123-
"""Calculate execution time of specified function."""
124-
start_time = time.time()
125-
func(*args, **kwargs)
126-
finish_time = time.time()
127-
128-
return finish_time - start_time
129-
130-
131-
def calc_compile_time(func, *args, **kwargs):
132-
"""Calculate compile time as difference between first 2 runs."""
133-
return calc_time(func, *args, **kwargs) - calc_time(func, *args, **kwargs)
134-
135-
136-
def calc_compilation(pyfunc, data, iter_number=5):
137-
"""Calculate compile time several times."""
138-
compile_times = []
139-
for _ in range(iter_number):
140-
with do_jit(pyfunc) as cfunc:
141-
compile_time = calc_compile_time(cfunc, data)
142-
compile_times.append(compile_time)
143-
144-
return compile_times
145-
146-
147-
def get_times(f, test_data, iter_number=5):
148-
"""Get time of boxing+unboxing and internal execution"""
149-
exec_times = []
150-
boxing_times = []
151-
for _ in range(iter_number):
152-
ext_start = time.time()
153-
int_result = f(test_data)
154-
ext_finish = time.time()
155-
156-
exec_times.append(int_result)
157-
boxing_times.append(max(ext_finish - ext_start - int_result, 0))
158-
159-
return exec_times, boxing_times
160-
161-
162-
class TestSeriesStringMethods(TestBase):
163115
@classmethod
164116
def setUpClass(cls):
165-
super().setUpClass()
166-
cls.total_data_length = [10**4 + 513, 10**5 + 2025]
117+
cls.test_results = TestResultsStr()
118+
if is_true(os.environ.get('LOAD_PREV_RESULTS')):
119+
cls.test_results.load()
120+
121+
cls.total_data_length = [10**4, 10**5]
167122
cls.width = [16, 64, 512, 1024]
123+
cls.num_threads = int(os.environ.get('NUMBA_NUM_THREADS', config.NUMBA_NUM_THREADS))
124+
cls.threading_layer = os.environ.get('NUMBA_THREADING_LAYER', config.THREADING_LAYER)
125+
126+
@classmethod
127+
def tearDownClass(cls):
128+
cls.test_results.print()
129+
cls.test_results.dump()
168130

169131
def _test_series_str(self, pyfunc, name, input_data=None):
170132
input_data = input_data or test_global_input_data_unicode_kind4

sdc/tests/tests_perf/test_perf_unicode.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
# *****************************************************************************
2727

2828
import unittest
29+
import os
2930
import time
3031
import numba
3132

3233
from sdc.tests.test_utils import *
33-
from sdc.tests.tests_perf.test_perf_base import TestBase
3434
from sdc.tests.tests_perf.test_perf_utils import *
3535

3636

@@ -92,10 +92,13 @@ def usecase_center(input_data):
9292
return iter_time
9393

9494

95-
class TestStringMethods(TestBase):
95+
class TestStringMethods(unittest.TestCase):
9696
@classmethod
9797
def setUpClass(cls):
98-
super().setUpClass()
98+
cls.test_results = TestResultsStr()
99+
if is_true(os.environ.get('LOAD_PREV_RESULTS')):
100+
cls.test_results.load()
101+
99102
cls.total_data_size_bytes = [1.0E+07]
100103
cls.width = [16, 64, 512, 1024]
101104

0 commit comments

Comments
 (0)