1 #include "perf_precomp.hpp"
2
3 using namespace std;
4 using namespace cv;
5 using namespace perf;
6 using std::tr1::make_tuple;
7 using std::tr1::get;
8
9 #define TYPICAL_MAT_SIZES_CORE_ARITHM ::szVGA, ::sz720p, ::sz1080p
10 #define TYPICAL_MAT_TYPES_CORE_ARITHM CV_8UC1, CV_8SC1, CV_16SC1, CV_16SC2, CV_16SC3, CV_16SC4, CV_8UC4, CV_32SC1, CV_32FC1
11 #define TYPICAL_MATS_CORE_ARITHM testing::Combine( testing::Values( TYPICAL_MAT_SIZES_CORE_ARITHM ), testing::Values( TYPICAL_MAT_TYPES_CORE_ARITHM ) )
12
PERF_TEST_P(Size_MatType,min,TYPICAL_MATS_CORE_ARITHM)13 PERF_TEST_P(Size_MatType, min, TYPICAL_MATS_CORE_ARITHM)
14 {
15 Size sz = get<0>(GetParam());
16 int type = get<1>(GetParam());
17 cv::Mat a = Mat(sz, type);
18 cv::Mat b = Mat(sz, type);
19 cv::Mat c = Mat(sz, type);
20
21 declare.in(a, b, WARMUP_RNG).out(c);
22
23 TEST_CYCLE() min(a, b, c);
24
25 SANITY_CHECK(c);
26 }
27
PERF_TEST_P(Size_MatType,minScalar,TYPICAL_MATS_CORE_ARITHM)28 PERF_TEST_P(Size_MatType, minScalar, TYPICAL_MATS_CORE_ARITHM)
29 {
30 Size sz = get<0>(GetParam());
31 int type = get<1>(GetParam());
32 cv::Mat a = Mat(sz, type);
33 cv::Scalar b;
34 cv::Mat c = Mat(sz, type);
35
36 declare.in(a, b, WARMUP_RNG).out(c);
37
38 TEST_CYCLE() min(a, b, c);
39
40 SANITY_CHECK(c);
41 }
42
PERF_TEST_P(Size_MatType,max,TYPICAL_MATS_CORE_ARITHM)43 PERF_TEST_P(Size_MatType, max, TYPICAL_MATS_CORE_ARITHM)
44 {
45 Size sz = get<0>(GetParam());
46 int type = get<1>(GetParam());
47 cv::Mat a = Mat(sz, type);
48 cv::Mat b = Mat(sz, type);
49 cv::Mat c = Mat(sz, type);
50
51 declare.in(a, b, WARMUP_RNG).out(c);
52
53 TEST_CYCLE() max(a, b, c);
54
55 SANITY_CHECK(c);
56 }
57
PERF_TEST_P(Size_MatType,maxScalar,TYPICAL_MATS_CORE_ARITHM)58 PERF_TEST_P(Size_MatType, maxScalar, TYPICAL_MATS_CORE_ARITHM)
59 {
60 Size sz = get<0>(GetParam());
61 int type = get<1>(GetParam());
62 cv::Mat a = Mat(sz, type);
63 cv::Scalar b;
64 cv::Mat c = Mat(sz, type);
65
66 declare.in(a, b, WARMUP_RNG).out(c);
67
68 TEST_CYCLE() max(a, b, c);
69
70 SANITY_CHECK(c);
71 }
72
PERF_TEST_P(Size_MatType,absdiff,TYPICAL_MATS_CORE_ARITHM)73 PERF_TEST_P(Size_MatType, absdiff, TYPICAL_MATS_CORE_ARITHM)
74 {
75 Size sz = get<0>(GetParam());
76 int type = get<1>(GetParam());
77 cv::Mat a = Mat(sz, type);
78 cv::Mat b = Mat(sz, type);
79 cv::Mat c = Mat(sz, type);
80
81 declare.in(a, b, WARMUP_RNG).out(c);
82
83 if (CV_MAT_DEPTH(type) == CV_32S)
84 {
85 //see ticket 1529: absdiff can be without saturation on 32S
86 a /= 2;
87 b /= 2;
88 }
89
90 TEST_CYCLE() absdiff(a, b, c);
91
92 SANITY_CHECK(c, 1e-8);
93 }
94
PERF_TEST_P(Size_MatType,absdiffScalar,TYPICAL_MATS_CORE_ARITHM)95 PERF_TEST_P(Size_MatType, absdiffScalar, TYPICAL_MATS_CORE_ARITHM)
96 {
97 Size sz = get<0>(GetParam());
98 int type = get<1>(GetParam());
99 cv::Mat a = Mat(sz, type);
100 cv::Scalar b;
101 cv::Mat c = Mat(sz, type);
102
103 declare.in(a, b, WARMUP_RNG).out(c);
104
105 if (CV_MAT_DEPTH(type) == CV_32S)
106 {
107 //see ticket 1529: absdiff can be without saturation on 32S
108 a /= 2;
109 b /= 2;
110 }
111
112 TEST_CYCLE() absdiff(a, b, c);
113
114 SANITY_CHECK(c, 1e-8);
115 }
116
PERF_TEST_P(Size_MatType,add,TYPICAL_MATS_CORE_ARITHM)117 PERF_TEST_P(Size_MatType, add, TYPICAL_MATS_CORE_ARITHM)
118 {
119 Size sz = get<0>(GetParam());
120 int type = get<1>(GetParam());
121 cv::Mat a = Mat(sz, type);
122 cv::Mat b = Mat(sz, type);
123 cv::Mat c = Mat(sz, type);
124
125 declare.in(a, b, WARMUP_RNG).out(c);
126 declare.time(50);
127
128 if (CV_MAT_DEPTH(type) == CV_32S)
129 {
130 //see ticket 1529: add can be without saturation on 32S
131 a /= 2;
132 b /= 2;
133 }
134
135 TEST_CYCLE() add(a, b, c);
136
137 SANITY_CHECK(c, 1e-8);
138 }
139
PERF_TEST_P(Size_MatType,addScalar,TYPICAL_MATS_CORE_ARITHM)140 PERF_TEST_P(Size_MatType, addScalar, TYPICAL_MATS_CORE_ARITHM)
141 {
142 Size sz = get<0>(GetParam());
143 int type = get<1>(GetParam());
144 cv::Mat a = Mat(sz, type);
145 cv::Scalar b;
146 cv::Mat c = Mat(sz, type);
147
148 declare.in(a, b, WARMUP_RNG).out(c);
149
150 if (CV_MAT_DEPTH(type) == CV_32S)
151 {
152 //see ticket 1529: add can be without saturation on 32S
153 a /= 2;
154 b /= 2;
155 }
156
157 TEST_CYCLE() add(a, b, c);
158
159 SANITY_CHECK(c, 1e-8);
160 }
161
PERF_TEST_P(Size_MatType,subtract,TYPICAL_MATS_CORE_ARITHM)162 PERF_TEST_P(Size_MatType, subtract, TYPICAL_MATS_CORE_ARITHM)
163 {
164 Size sz = get<0>(GetParam());
165 int type = get<1>(GetParam());
166 cv::Mat a = Mat(sz, type);
167 cv::Mat b = Mat(sz, type);
168 cv::Mat c = Mat(sz, type);
169
170 declare.in(a, b, WARMUP_RNG).out(c);
171
172 if (CV_MAT_DEPTH(type) == CV_32S)
173 {
174 //see ticket 1529: subtract can be without saturation on 32S
175 a /= 2;
176 b /= 2;
177 }
178
179 TEST_CYCLE() subtract(a, b, c);
180
181 SANITY_CHECK(c, 1e-8);
182 }
183
PERF_TEST_P(Size_MatType,subtractScalar,TYPICAL_MATS_CORE_ARITHM)184 PERF_TEST_P(Size_MatType, subtractScalar, TYPICAL_MATS_CORE_ARITHM)
185 {
186 Size sz = get<0>(GetParam());
187 int type = get<1>(GetParam());
188 cv::Mat a = Mat(sz, type);
189 cv::Scalar b;
190 cv::Mat c = Mat(sz, type);
191
192 declare.in(a, b, WARMUP_RNG).out(c);
193
194 if (CV_MAT_DEPTH(type) == CV_32S)
195 {
196 //see ticket 1529: subtract can be without saturation on 32S
197 a /= 2;
198 b /= 2;
199 }
200
201 TEST_CYCLE() subtract(a, b, c);
202
203 SANITY_CHECK(c, 1e-8);
204 }
205
PERF_TEST_P(Size_MatType,multiply,TYPICAL_MATS_CORE_ARITHM)206 PERF_TEST_P(Size_MatType, multiply, TYPICAL_MATS_CORE_ARITHM)
207 {
208 Size sz = get<0>(GetParam());
209 int type = get<1>(GetParam());
210 cv::Mat a(sz, type), b(sz, type), c(sz, type);
211
212 declare.in(a, b, WARMUP_RNG).out(c);
213 if (CV_MAT_DEPTH(type) == CV_32S)
214 {
215 //According to docs, saturation is not applied when result is 32bit integer
216 a /= (2 << 16);
217 b /= (2 << 16);
218 }
219
220 TEST_CYCLE() multiply(a, b, c);
221
222 SANITY_CHECK(c, 1e-8);
223 }
224
PERF_TEST_P(Size_MatType,multiplyScale,TYPICAL_MATS_CORE_ARITHM)225 PERF_TEST_P(Size_MatType, multiplyScale, TYPICAL_MATS_CORE_ARITHM)
226 {
227 Size sz = get<0>(GetParam());
228 int type = get<1>(GetParam());
229 cv::Mat a(sz, type), b(sz, type), c(sz, type);
230 double scale = 0.5;
231
232 declare.in(a, b, WARMUP_RNG).out(c);
233
234 if (CV_MAT_DEPTH(type) == CV_32S)
235 {
236 //According to docs, saturation is not applied when result is 32bit integer
237 a /= (2 << 16);
238 b /= (2 << 16);
239 }
240
241 TEST_CYCLE() multiply(a, b, c, scale);
242
243 SANITY_CHECK(c, 1e-8);
244 }
245
PERF_TEST_P(Size_MatType,divide,TYPICAL_MATS_CORE_ARITHM)246 PERF_TEST_P(Size_MatType, divide, TYPICAL_MATS_CORE_ARITHM)
247 {
248 Size sz = get<0>(GetParam());
249 int type = get<1>(GetParam());
250 cv::Mat a(sz, type), b(sz, type), c(sz, type);
251 double scale = 0.5;
252
253 declare.in(a, b, WARMUP_RNG).out(c);
254
255 TEST_CYCLE() divide(a, b, c, scale);
256
257 SANITY_CHECK_NOTHING();
258 }
259
PERF_TEST_P(Size_MatType,reciprocal,TYPICAL_MATS_CORE_ARITHM)260 PERF_TEST_P(Size_MatType, reciprocal, TYPICAL_MATS_CORE_ARITHM)
261 {
262 Size sz = get<0>(GetParam());
263 int type = get<1>(GetParam());
264 cv::Mat b(sz, type), c(sz, type);
265 double scale = 0.5;
266
267 declare.in(b, WARMUP_RNG).out(c);
268
269 TEST_CYCLE() divide(scale, b, c);
270
271 SANITY_CHECK_NOTHING();
272 }
273