aboutsummaryrefslogtreecommitdiff
path: root/bench/throughput.cc
blob: 2242ccb3854e9d6e615446f487f752e9c5aa5430 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <benchmark/benchmark.h>

#include <pthreadpool.h>


static void compute_1d(void*, size_t) {
}

static void pthreadpool_parallelize_1d(benchmark::State& state) {
	pthreadpool_t threadpool = pthreadpool_create(0);
	const size_t threads = pthreadpool_get_threads_count(threadpool);
	const size_t items = static_cast<size_t>(state.range(0));
	while (state.KeepRunning()) {
		pthreadpool_parallelize_1d(
			threadpool,
			compute_1d,
			nullptr /* context */,
			items * threads,
			0 /* flags */);
	}
	pthreadpool_destroy(threadpool);

	/* Do not normalize by thread */
	state.SetItemsProcessed(int64_t(state.iterations()) * items);
}
BENCHMARK(pthreadpool_parallelize_1d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);


static void compute_1d_tile_1d(void*, size_t, size_t) {
}

static void pthreadpool_parallelize_1d_tile_1d(benchmark::State& state) {
	pthreadpool_t threadpool = pthreadpool_create(0);
	const size_t threads = pthreadpool_get_threads_count(threadpool);
	const size_t items = static_cast<size_t>(state.range(0));
	while (state.KeepRunning()) {
		pthreadpool_parallelize_1d_tile_1d(
			threadpool,
			compute_1d_tile_1d,
			nullptr /* context */,
			items * threads, 1,
			0 /* flags */);
	}
	pthreadpool_destroy(threadpool);

	/* Do not normalize by thread */
	state.SetItemsProcessed(int64_t(state.iterations()) * items);
}
BENCHMARK(pthreadpool_parallelize_1d_tile_1d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);


static void compute_2d(void* context, size_t x, size_t y) {
}

static void pthreadpool_parallelize_2d(benchmark::State& state) {
	pthreadpool_t threadpool = pthreadpool_create(0);
	const size_t threads = pthreadpool_get_threads_count(threadpool);
	const size_t items = static_cast<size_t>(state.range(0));
	while (state.KeepRunning()) {
		pthreadpool_parallelize_2d(
			threadpool,
			compute_2d,
			nullptr /* context */,
			threads, items,
			0 /* flags */);
	}
	pthreadpool_destroy(threadpool);

	/* Do not normalize by thread */
	state.SetItemsProcessed(int64_t(state.iterations()) * items);
}
BENCHMARK(pthreadpool_parallelize_2d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);


static void compute_2d_tiled(void* context, size_t x0, size_t y0, size_t xn, size_t yn) {
}

static void pthreadpool_parallelize_2d_tile_2d(benchmark::State& state) {
	pthreadpool_t threadpool = pthreadpool_create(0);
	const size_t threads = pthreadpool_get_threads_count(threadpool);
	const size_t items = static_cast<size_t>(state.range(0));
	while (state.KeepRunning()) {
		pthreadpool_parallelize_2d_tile_2d(
			threadpool,
			compute_2d_tiled,
			nullptr /* context */,
			threads, items,
			1, 1,
			0 /* flags */);
	}
	pthreadpool_destroy(threadpool);

	/* Do not normalize by thread */
	state.SetItemsProcessed(int64_t(state.iterations()) * items);
}
BENCHMARK(pthreadpool_parallelize_2d_tile_2d)->UseRealTime()->RangeMultiplier(10)->Range(10, 1000000);


BENCHMARK_MAIN();