• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <benchmark/benchmark.h>
2 
3 #include <pthreadpool.h>
4 
5 #include <thread>
6 
SetNumberOfThreads(benchmark::internal::Benchmark * benchmark)7 static void SetNumberOfThreads(benchmark::internal::Benchmark* benchmark) {
8 	const int max_threads = std::thread::hardware_concurrency();
9 	for (int t = 1; t <= max_threads; t++) {
10 		benchmark->Arg(t);
11 	}
12 }
13 
14 
compute_1d(void *,size_t x)15 static void compute_1d(void*, size_t x) {
16 }
17 
pthreadpool_parallelize_1d(benchmark::State & state)18 static void pthreadpool_parallelize_1d(benchmark::State& state) {
19 	const uint32_t threads = static_cast<uint32_t>(state.range(0));
20 	pthreadpool_t threadpool = pthreadpool_create(threads);
21 	while (state.KeepRunning()) {
22 		pthreadpool_parallelize_1d(
23 			threadpool,
24 			compute_1d,
25 			nullptr /* context */,
26 			threads,
27 			0 /* flags */);
28 	}
29 	pthreadpool_destroy(threadpool);
30 }
31 BENCHMARK(pthreadpool_parallelize_1d)->UseRealTime()->Apply(SetNumberOfThreads);
32 
33 
compute_1d_tile_1d(void *,size_t,size_t)34 static void compute_1d_tile_1d(void*, size_t, size_t) {
35 }
36 
pthreadpool_parallelize_1d_tile_1d(benchmark::State & state)37 static void pthreadpool_parallelize_1d_tile_1d(benchmark::State& state) {
38 	const uint32_t threads = static_cast<uint32_t>(state.range(0));
39 	pthreadpool_t threadpool = pthreadpool_create(threads);
40 	while (state.KeepRunning()) {
41 		pthreadpool_parallelize_1d_tile_1d(
42 			threadpool,
43 			compute_1d_tile_1d,
44 			nullptr /* context */,
45 			threads, 1,
46 			0 /* flags */);
47 	}
48 	pthreadpool_destroy(threadpool);
49 }
50 BENCHMARK(pthreadpool_parallelize_1d_tile_1d)->UseRealTime()->Apply(SetNumberOfThreads);
51 
52 
compute_2d(void *,size_t,size_t)53 static void compute_2d(void*, size_t, size_t) {
54 }
55 
pthreadpool_parallelize_2d(benchmark::State & state)56 static void pthreadpool_parallelize_2d(benchmark::State& state) {
57 	const uint32_t threads = static_cast<uint32_t>(state.range(0));
58 	pthreadpool_t threadpool = pthreadpool_create(threads);
59 	while (state.KeepRunning()) {
60 		pthreadpool_parallelize_2d(
61 			threadpool,
62 			compute_2d,
63 			nullptr /* context */,
64 			1, threads,
65 			0 /* flags */);
66 	}
67 	pthreadpool_destroy(threadpool);
68 }
69 BENCHMARK(pthreadpool_parallelize_2d)->UseRealTime()->Apply(SetNumberOfThreads);
70 
71 
compute_2d_tile_2d(void *,size_t,size_t,size_t,size_t)72 static void compute_2d_tile_2d(void*, size_t, size_t, size_t, size_t) {
73 }
74 
pthreadpool_parallelize_2d_tile_2d(benchmark::State & state)75 static void pthreadpool_parallelize_2d_tile_2d(benchmark::State& state) {
76 	const uint32_t threads = static_cast<uint32_t>(state.range(0));
77 	pthreadpool_t threadpool = pthreadpool_create(threads);
78 	while (state.KeepRunning()) {
79 		pthreadpool_parallelize_2d_tile_2d(
80 			threadpool,
81 			compute_2d_tile_2d,
82 			nullptr /* context */,
83 			1, threads,
84 			1, 1,
85 			0 /* flags */);
86 	}
87 	pthreadpool_destroy(threadpool);
88 }
89 BENCHMARK(pthreadpool_parallelize_2d_tile_2d)->UseRealTime()->Apply(SetNumberOfThreads);
90 
91 
92 BENCHMARK_MAIN();
93