• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <benchmark/benchmark.h>
2 
3 #include <pthreadpool.h>
4 
5 
compute_1d(void *,size_t)6 static void compute_1d(void*, size_t) {
7 }
8 
pthreadpool_parallelize_1d(benchmark::State & state)9 static void pthreadpool_parallelize_1d(benchmark::State& state) {
10 	pthreadpool_t threadpool = pthreadpool_create(2);
11 	const size_t threads = pthreadpool_get_threads_count(threadpool);
12 	const size_t items = static_cast<size_t>(state.range(0));
13 	while (state.KeepRunning()) {
14 		pthreadpool_parallelize_1d(
15 			threadpool,
16 			compute_1d,
17 			nullptr /* context */,
18 			items * threads,
19 			0 /* flags */);
20 	}
21 	pthreadpool_destroy(threadpool);
22 
23 	/* Do not normalize by thread */
24 	state.SetItemsProcessed(int64_t(state.iterations()) * items);
25 }
26 BENCHMARK(pthreadpool_parallelize_1d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);
27 
28 
compute_1d_tile_1d(void *,size_t,size_t)29 static void compute_1d_tile_1d(void*, size_t, size_t) {
30 }
31 
pthreadpool_parallelize_1d_tile_1d(benchmark::State & state)32 static void pthreadpool_parallelize_1d_tile_1d(benchmark::State& state) {
33 	pthreadpool_t threadpool = pthreadpool_create(2);
34 	const size_t threads = pthreadpool_get_threads_count(threadpool);
35 	const size_t items = static_cast<size_t>(state.range(0));
36 	while (state.KeepRunning()) {
37 		pthreadpool_parallelize_1d_tile_1d(
38 			threadpool,
39 			compute_1d_tile_1d,
40 			nullptr /* context */,
41 			items * threads, 1,
42 			0 /* flags */);
43 	}
44 	pthreadpool_destroy(threadpool);
45 
46 	/* Do not normalize by thread */
47 	state.SetItemsProcessed(int64_t(state.iterations()) * items);
48 }
49 BENCHMARK(pthreadpool_parallelize_1d_tile_1d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);
50 
51 
compute_2d(void *,size_t,size_t)52 static void compute_2d(void*, size_t, size_t) {
53 }
54 
pthreadpool_parallelize_2d(benchmark::State & state)55 static void pthreadpool_parallelize_2d(benchmark::State& state) {
56 	pthreadpool_t threadpool = pthreadpool_create(2);
57 	const size_t threads = pthreadpool_get_threads_count(threadpool);
58 	const size_t items = static_cast<size_t>(state.range(0));
59 	while (state.KeepRunning()) {
60 		pthreadpool_parallelize_2d(
61 			threadpool,
62 			compute_2d,
63 			nullptr /* context */,
64 			threads, items,
65 			0 /* flags */);
66 	}
67 	pthreadpool_destroy(threadpool);
68 
69 	/* Do not normalize by thread */
70 	state.SetItemsProcessed(int64_t(state.iterations()) * items);
71 }
72 BENCHMARK(pthreadpool_parallelize_2d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);
73 
74 
compute_2d_tile_1d(void *,size_t,size_t,size_t)75 static void compute_2d_tile_1d(void*, size_t, size_t, size_t) {
76 }
77 
pthreadpool_parallelize_2d_tile_1d(benchmark::State & state)78 static void pthreadpool_parallelize_2d_tile_1d(benchmark::State& state) {
79 	pthreadpool_t threadpool = pthreadpool_create(2);
80 	const size_t threads = pthreadpool_get_threads_count(threadpool);
81 	const size_t items = static_cast<size_t>(state.range(0));
82 	while (state.KeepRunning()) {
83 		pthreadpool_parallelize_2d_tile_1d(
84 			threadpool,
85 			compute_2d_tile_1d,
86 			nullptr /* context */,
87 			threads, items,
88 			1,
89 			0 /* flags */);
90 	}
91 	pthreadpool_destroy(threadpool);
92 
93 	/* Do not normalize by thread */
94 	state.SetItemsProcessed(int64_t(state.iterations()) * items);
95 }
96 BENCHMARK(pthreadpool_parallelize_2d_tile_1d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);
97 
98 
compute_2d_tile_2d(void *,size_t,size_t,size_t,size_t)99 static void compute_2d_tile_2d(void*, size_t, size_t, size_t, size_t) {
100 }
101 
pthreadpool_parallelize_2d_tile_2d(benchmark::State & state)102 static void pthreadpool_parallelize_2d_tile_2d(benchmark::State& state) {
103 	pthreadpool_t threadpool = pthreadpool_create(2);
104 	const size_t threads = pthreadpool_get_threads_count(threadpool);
105 	const size_t items = static_cast<size_t>(state.range(0));
106 	while (state.KeepRunning()) {
107 		pthreadpool_parallelize_2d_tile_2d(
108 			threadpool,
109 			compute_2d_tile_2d,
110 			nullptr /* context */,
111 			threads, items,
112 			1, 1,
113 			0 /* flags */);
114 	}
115 	pthreadpool_destroy(threadpool);
116 
117 	/* Do not normalize by thread */
118 	state.SetItemsProcessed(int64_t(state.iterations()) * items);
119 }
120 BENCHMARK(pthreadpool_parallelize_2d_tile_2d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);
121 
122 
compute_3d(void *,size_t,size_t,size_t)123 static void compute_3d(void*, size_t, size_t, size_t) {
124 }
125 
pthreadpool_parallelize_3d(benchmark::State & state)126 static void pthreadpool_parallelize_3d(benchmark::State& state) {
127 	pthreadpool_t threadpool = pthreadpool_create(2);
128 	const size_t threads = pthreadpool_get_threads_count(threadpool);
129 	const size_t items = static_cast<size_t>(state.range(0));
130 	while (state.KeepRunning()) {
131 		pthreadpool_parallelize_3d(
132 			threadpool,
133 			compute_3d,
134 			nullptr /* context */,
135 			1, threads, items,
136 			0 /* flags */);
137 	}
138 	pthreadpool_destroy(threadpool);
139 
140 	/* Do not normalize by thread */
141 	state.SetItemsProcessed(int64_t(state.iterations()) * items);
142 }
143 BENCHMARK(pthreadpool_parallelize_3d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);
144 
145 
compute_3d_tile_1d(void *,size_t,size_t,size_t,size_t)146 static void compute_3d_tile_1d(void*, size_t, size_t, size_t, size_t) {
147 }
148 
pthreadpool_parallelize_3d_tile_1d(benchmark::State & state)149 static void pthreadpool_parallelize_3d_tile_1d(benchmark::State& state) {
150 	pthreadpool_t threadpool = pthreadpool_create(2);
151 	const size_t threads = pthreadpool_get_threads_count(threadpool);
152 	const size_t items = static_cast<size_t>(state.range(0));
153 	while (state.KeepRunning()) {
154 		pthreadpool_parallelize_3d_tile_1d(
155 			threadpool,
156 			compute_3d_tile_1d,
157 			nullptr /* context */,
158 			1, threads, items,
159 			1,
160 			0 /* flags */);
161 	}
162 	pthreadpool_destroy(threadpool);
163 
164 	/* Do not normalize by thread */
165 	state.SetItemsProcessed(int64_t(state.iterations()) * items);
166 }
167 BENCHMARK(pthreadpool_parallelize_3d_tile_1d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);
168 
169 
compute_3d_tile_2d(void *,size_t,size_t,size_t,size_t,size_t)170 static void compute_3d_tile_2d(void*, size_t, size_t, size_t, size_t, size_t) {
171 }
172 
pthreadpool_parallelize_3d_tile_2d(benchmark::State & state)173 static void pthreadpool_parallelize_3d_tile_2d(benchmark::State& state) {
174 	pthreadpool_t threadpool = pthreadpool_create(2);
175 	const size_t threads = pthreadpool_get_threads_count(threadpool);
176 	const size_t items = static_cast<size_t>(state.range(0));
177 	while (state.KeepRunning()) {
178 		pthreadpool_parallelize_3d_tile_2d(
179 			threadpool,
180 			compute_3d_tile_2d,
181 			nullptr /* context */,
182 			1, threads, items,
183 			1, 1,
184 			0 /* flags */);
185 	}
186 	pthreadpool_destroy(threadpool);
187 
188 	/* Do not normalize by thread */
189 	state.SetItemsProcessed(int64_t(state.iterations()) * items);
190 }
191 BENCHMARK(pthreadpool_parallelize_3d_tile_2d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);
192 
193 
compute_4d(void *,size_t,size_t,size_t,size_t)194 static void compute_4d(void*, size_t, size_t, size_t, size_t) {
195 }
196 
pthreadpool_parallelize_4d(benchmark::State & state)197 static void pthreadpool_parallelize_4d(benchmark::State& state) {
198 	pthreadpool_t threadpool = pthreadpool_create(2);
199 	const size_t threads = pthreadpool_get_threads_count(threadpool);
200 	const size_t items = static_cast<size_t>(state.range(0));
201 	while (state.KeepRunning()) {
202 		pthreadpool_parallelize_4d(
203 			threadpool,
204 			compute_4d,
205 			nullptr /* context */,
206 			1, 1, threads, items,
207 			0 /* flags */);
208 	}
209 	pthreadpool_destroy(threadpool);
210 
211 	/* Do not normalize by thread */
212 	state.SetItemsProcessed(int64_t(state.iterations()) * items);
213 }
214 BENCHMARK(pthreadpool_parallelize_4d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);
215 
216 
compute_4d_tile_1d(void *,size_t,size_t,size_t,size_t,size_t)217 static void compute_4d_tile_1d(void*, size_t, size_t, size_t, size_t, size_t) {
218 }
219 
pthreadpool_parallelize_4d_tile_1d(benchmark::State & state)220 static void pthreadpool_parallelize_4d_tile_1d(benchmark::State& state) {
221 	pthreadpool_t threadpool = pthreadpool_create(2);
222 	const size_t threads = pthreadpool_get_threads_count(threadpool);
223 	const size_t items = static_cast<size_t>(state.range(0));
224 	while (state.KeepRunning()) {
225 		pthreadpool_parallelize_4d_tile_1d(
226 			threadpool,
227 			compute_4d_tile_1d,
228 			nullptr /* context */,
229 			1, 1, threads, items,
230 			1,
231 			0 /* flags */);
232 	}
233 	pthreadpool_destroy(threadpool);
234 
235 	/* Do not normalize by thread */
236 	state.SetItemsProcessed(int64_t(state.iterations()) * items);
237 }
238 BENCHMARK(pthreadpool_parallelize_4d_tile_1d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);
239 
240 
compute_4d_tile_2d(void *,size_t,size_t,size_t,size_t,size_t,size_t)241 static void compute_4d_tile_2d(void*, size_t, size_t, size_t, size_t, size_t, size_t) {
242 }
243 
pthreadpool_parallelize_4d_tile_2d(benchmark::State & state)244 static void pthreadpool_parallelize_4d_tile_2d(benchmark::State& state) {
245 	pthreadpool_t threadpool = pthreadpool_create(2);
246 	const size_t threads = pthreadpool_get_threads_count(threadpool);
247 	const size_t items = static_cast<size_t>(state.range(0));
248 	while (state.KeepRunning()) {
249 		pthreadpool_parallelize_4d_tile_2d(
250 			threadpool,
251 			compute_4d_tile_2d,
252 			nullptr /* context */,
253 			1, 1, threads, items,
254 			1, 1,
255 			0 /* flags */);
256 	}
257 	pthreadpool_destroy(threadpool);
258 
259 	/* Do not normalize by thread */
260 	state.SetItemsProcessed(int64_t(state.iterations()) * items);
261 }
262 BENCHMARK(pthreadpool_parallelize_4d_tile_2d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);
263 
264 
compute_5d(void *,size_t,size_t,size_t,size_t,size_t)265 static void compute_5d(void*, size_t, size_t, size_t, size_t, size_t) {
266 }
267 
pthreadpool_parallelize_5d(benchmark::State & state)268 static void pthreadpool_parallelize_5d(benchmark::State& state) {
269 	pthreadpool_t threadpool = pthreadpool_create(2);
270 	const size_t threads = pthreadpool_get_threads_count(threadpool);
271 	const size_t items = static_cast<size_t>(state.range(0));
272 	while (state.KeepRunning()) {
273 		pthreadpool_parallelize_5d(
274 			threadpool,
275 			compute_5d,
276 			nullptr /* context */,
277 			1, 1, 1, threads, items,
278 			0 /* flags */);
279 	}
280 	pthreadpool_destroy(threadpool);
281 
282 	/* Do not normalize by thread */
283 	state.SetItemsProcessed(int64_t(state.iterations()) * items);
284 }
285 BENCHMARK(pthreadpool_parallelize_5d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);
286 
287 
compute_5d_tile_1d(void *,size_t,size_t,size_t,size_t,size_t,size_t)288 static void compute_5d_tile_1d(void*, size_t, size_t, size_t, size_t, size_t, size_t) {
289 }
290 
pthreadpool_parallelize_5d_tile_1d(benchmark::State & state)291 static void pthreadpool_parallelize_5d_tile_1d(benchmark::State& state) {
292 	pthreadpool_t threadpool = pthreadpool_create(2);
293 	const size_t threads = pthreadpool_get_threads_count(threadpool);
294 	const size_t items = static_cast<size_t>(state.range(0));
295 	while (state.KeepRunning()) {
296 		pthreadpool_parallelize_5d_tile_1d(
297 			threadpool,
298 			compute_5d_tile_1d,
299 			nullptr /* context */,
300 			1, 1, 1, threads, items,
301 			1,
302 			0 /* flags */);
303 	}
304 	pthreadpool_destroy(threadpool);
305 
306 	/* Do not normalize by thread */
307 	state.SetItemsProcessed(int64_t(state.iterations()) * items);
308 }
309 BENCHMARK(pthreadpool_parallelize_5d_tile_1d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);
310 
311 
compute_5d_tile_2d(void *,size_t,size_t,size_t,size_t,size_t,size_t,size_t)312 static void compute_5d_tile_2d(void*, size_t, size_t, size_t, size_t, size_t, size_t, size_t) {
313 }
314 
pthreadpool_parallelize_5d_tile_2d(benchmark::State & state)315 static void pthreadpool_parallelize_5d_tile_2d(benchmark::State& state) {
316 	pthreadpool_t threadpool = pthreadpool_create(2);
317 	const size_t threads = pthreadpool_get_threads_count(threadpool);
318 	const size_t items = static_cast<size_t>(state.range(0));
319 	while (state.KeepRunning()) {
320 		pthreadpool_parallelize_5d_tile_2d(
321 			threadpool,
322 			compute_5d_tile_2d,
323 			nullptr /* context */,
324 			1, 1, 1, threads, items,
325 			1, 1,
326 			0 /* flags */);
327 	}
328 	pthreadpool_destroy(threadpool);
329 
330 	/* Do not normalize by thread */
331 	state.SetItemsProcessed(int64_t(state.iterations()) * items);
332 }
333 BENCHMARK(pthreadpool_parallelize_5d_tile_2d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);
334 
335 
compute_6d(void *,size_t,size_t,size_t,size_t,size_t,size_t)336 static void compute_6d(void*, size_t, size_t, size_t, size_t, size_t, size_t) {
337 }
338 
pthreadpool_parallelize_6d(benchmark::State & state)339 static void pthreadpool_parallelize_6d(benchmark::State& state) {
340 	pthreadpool_t threadpool = pthreadpool_create(2);
341 	const size_t threads = pthreadpool_get_threads_count(threadpool);
342 	const size_t items = static_cast<size_t>(state.range(0));
343 	while (state.KeepRunning()) {
344 		pthreadpool_parallelize_6d(
345 			threadpool,
346 			compute_6d,
347 			nullptr /* context */,
348 			1, 1, 1, 1, threads, items,
349 			0 /* flags */);
350 	}
351 	pthreadpool_destroy(threadpool);
352 
353 	/* Do not normalize by thread */
354 	state.SetItemsProcessed(int64_t(state.iterations()) * items);
355 }
356 BENCHMARK(pthreadpool_parallelize_6d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);
357 
358 
compute_6d_tile_1d(void *,size_t,size_t,size_t,size_t,size_t,size_t,size_t)359 static void compute_6d_tile_1d(void*, size_t, size_t, size_t, size_t, size_t, size_t, size_t) {
360 }
361 
pthreadpool_parallelize_6d_tile_1d(benchmark::State & state)362 static void pthreadpool_parallelize_6d_tile_1d(benchmark::State& state) {
363 	pthreadpool_t threadpool = pthreadpool_create(2);
364 	const size_t threads = pthreadpool_get_threads_count(threadpool);
365 	const size_t items = static_cast<size_t>(state.range(0));
366 	while (state.KeepRunning()) {
367 		pthreadpool_parallelize_6d_tile_1d(
368 			threadpool,
369 			compute_6d_tile_1d,
370 			nullptr /* context */,
371 			1, 1, 1, 1, threads, items,
372 			1,
373 			0 /* flags */);
374 	}
375 	pthreadpool_destroy(threadpool);
376 
377 	/* Do not normalize by thread */
378 	state.SetItemsProcessed(int64_t(state.iterations()) * items);
379 }
380 BENCHMARK(pthreadpool_parallelize_6d_tile_1d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);
381 
382 
compute_6d_tile_2d(void *,size_t,size_t,size_t,size_t,size_t,size_t,size_t,size_t)383 static void compute_6d_tile_2d(void*, size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t) {
384 }
385 
pthreadpool_parallelize_6d_tile_2d(benchmark::State & state)386 static void pthreadpool_parallelize_6d_tile_2d(benchmark::State& state) {
387 	pthreadpool_t threadpool = pthreadpool_create(2);
388 	const size_t threads = pthreadpool_get_threads_count(threadpool);
389 	const size_t items = static_cast<size_t>(state.range(0));
390 	while (state.KeepRunning()) {
391 		pthreadpool_parallelize_6d_tile_2d(
392 			threadpool,
393 			compute_6d_tile_2d,
394 			nullptr /* context */,
395 			1, 1, 1, 1, threads, items,
396 			1, 1,
397 			0 /* flags */);
398 	}
399 	pthreadpool_destroy(threadpool);
400 
401 	/* Do not normalize by thread */
402 	state.SetItemsProcessed(int64_t(state.iterations()) * items);
403 }
404 BENCHMARK(pthreadpool_parallelize_6d_tile_2d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);
405 
406 
407 BENCHMARK_MAIN();
408