|
26 | 26 | # ***************************************************************************** |
27 | 27 |
|
28 | 28 | import itertools |
| 29 | +import os |
29 | 30 | import time |
30 | 31 | import unittest |
31 | 32 | from contextlib import contextmanager |
32 | 33 |
|
33 | 34 | import pandas as pd |
34 | 35 |
|
35 | 36 | from sdc.tests.test_utils import * |
36 | | -from sdc.tests.tests_perf.test_perf_base import TestBase |
37 | 37 | from sdc.tests.tests_perf.test_perf_utils import * |
38 | 38 |
|
39 | 39 |
|
40 | 40 | def usecase_series_len(input_data): |
41 | 41 | start_time = time.time() |
42 | | - input_data.str.len() |
| 42 | + res = input_data.str.len() |
43 | 43 | finish_time = time.time() |
44 | 44 |
|
45 | | - return finish_time - start_time |
| 45 | + return finish_time - start_time, res |
46 | 46 |
|
47 | 47 |
|
48 | 48 | def usecase_series_capitalize(input_data): |
49 | 49 | start_time = time.time() |
50 | | - input_data.str.capitalize() |
| 50 | + res = input_data.str.capitalize() |
51 | 51 | finish_time = time.time() |
52 | 52 |
|
53 | | - return finish_time - start_time |
| 53 | + return finish_time - start_time, res |
54 | 54 |
|
55 | 55 |
|
56 | 56 | def usecase_series_lower(input_data): |
57 | 57 | start_time = time.time() |
58 | | - input_data.str.lower() |
| 58 | + res = input_data.str.lower() |
59 | 59 | finish_time = time.time() |
60 | 60 |
|
61 | | - return finish_time - start_time |
| 61 | + return finish_time - start_time, res |
62 | 62 |
|
63 | 63 |
|
64 | 64 | def usecase_series_swapcase(input_data): |
65 | 65 | start_time = time.time() |
66 | | - input_data.str.swapcase() |
| 66 | + res = input_data.str.swapcase() |
67 | 67 | finish_time = time.time() |
68 | 68 |
|
69 | | - return finish_time - start_time |
| 69 | + return finish_time - start_time, res |
70 | 70 |
|
71 | 71 |
|
72 | 72 | def usecase_series_title(input_data): |
73 | 73 | start_time = time.time() |
74 | | - input_data.str.title() |
| 74 | + res = input_data.str.title() |
75 | 75 | finish_time = time.time() |
76 | 76 |
|
77 | | - return finish_time - start_time |
| 77 | + return finish_time - start_time, res |
78 | 78 |
|
79 | 79 |
|
80 | 80 | def usecase_series_upper(input_data): |
81 | 81 | start_time = time.time() |
82 | | - input_data.str.upper() |
| 82 | + res = input_data.str.upper() |
83 | 83 | finish_time = time.time() |
84 | 84 |
|
85 | | - return finish_time - start_time |
| 85 | + return finish_time - start_time, res |
86 | 86 |
|
87 | 87 |
|
88 | 88 | def usecase_series_lstrip(input_data): |
89 | 89 | start_time = time.time() |
90 | | - input_data.str.lstrip() |
| 90 | + res = input_data.str.lstrip() |
91 | 91 | finish_time = time.time() |
92 | 92 |
|
93 | | - return finish_time - start_time |
| 93 | + return finish_time - start_time, res |
94 | 94 |
|
95 | 95 |
|
96 | 96 | def usecase_series_rstrip(input_data): |
97 | 97 | start_time = time.time() |
98 | | - input_data.str.rstrip() |
| 98 | + res = input_data.str.rstrip() |
99 | 99 | finish_time = time.time() |
100 | 100 |
|
101 | | - return finish_time - start_time |
| 101 | + return finish_time - start_time, res |
102 | 102 |
|
103 | 103 |
|
104 | 104 | def usecase_series_strip(input_data): |
105 | 105 | start_time = time.time() |
106 | | - input_data.str.strip() |
| 106 | + res = input_data.str.strip() |
107 | 107 | finish_time = time.time() |
108 | 108 |
|
109 | | - return finish_time - start_time |
| 109 | + return finish_time - start_time, res |
110 | 110 |
|
111 | 111 |
|
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 |
120 | 114 |
|
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): |
163 | 115 | @classmethod |
164 | 116 | 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] |
167 | 122 | 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() |
168 | 130 |
|
169 | 131 | def _test_series_str(self, pyfunc, name, input_data=None): |
170 | 132 | input_data = input_data or test_global_input_data_unicode_kind4 |
|
0 commit comments