1
1
/*
2
- * Copyright (C) 2024 Intel Corporation
2
+ * Copyright (C) 2024-2025 Intel Corporation
3
3
*
4
4
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
5
5
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
6
*
7
7
*/
8
-
9
8
#include " benchmark.hpp"
9
+ #include < benchmark/benchmark.h>
10
10
11
11
#define UMF_BENCHMARK_TEMPLATE_DEFINE (BaseClass, Method, ...) \
12
12
BENCHMARK_TEMPLATE_DEFINE_F (BaseClass, Method, __VA_ARGS__) \
18
18
19
19
#define UMF_BENCHMARK_REGISTER_F (BaseClass, Method ) \
20
20
BENCHMARK_REGISTER_F (BaseClass, Method) \
21
- ->ArgNames( \
22
- BENCHMARK_PRIVATE_CONCAT_NAME (BaseClass, Method)::argsName()) \
23
- ->Name(BENCHMARK_PRIVATE_CONCAT_NAME(BaseClass, Method)::name()) \
24
- ->Iterations( \
25
- BENCHMARK_PRIVATE_CONCAT_NAME (BaseClass, Method)::iterations())
26
-
27
- UMF_BENCHMARK_TEMPLATE_DEFINE(alloc_benchmark, glibc_fix, fixed_alloc_size,
28
- glibc_malloc);
21
+ ->Apply( \
22
+ &BENCHMARK_PRIVATE_CONCAT_NAME (BaseClass, Method)::defaultArgs)
29
23
30
24
// Benchmarks scenarios:
31
25
32
26
// The benchmark arguments specified in Args() are, in order:
33
27
// benchmark arguments, allocator arguments, size generator arguments.
34
28
// The exact meaning of each argument depends on the benchmark, allocator, and size components used.
35
29
// Refer to the 'argsName()' function in each component to find detailed descriptions of these arguments.
30
+
31
+ static void default_alloc_fix_size(benchmark::internal::Benchmark *benchmark) {
32
+ benchmark->Args ({10000 , 0 , 4096 });
33
+ benchmark->Args ({10000 , 100000 , 4096 });
34
+ benchmark->Threads (4 );
35
+ benchmark->Threads (1 );
36
+ }
37
+
38
+ static void
39
+ default_alloc_uniform_size (benchmark::internal::Benchmark *benchmark) {
40
+ benchmark->Args ({10000 , 0 , 8 , 64 * 1024 , 8 });
41
+ benchmark->Threads (4 );
42
+ benchmark->Threads (1 );
43
+ }
44
+
45
+ UMF_BENCHMARK_TEMPLATE_DEFINE (alloc_benchmark, glibc_fix, fixed_alloc_size,
46
+ glibc_malloc);
47
+
36
48
UMF_BENCHMARK_REGISTER_F (alloc_benchmark, glibc_fix)
37
- ->Args({10000 , 0 , 4096 })
38
- ->Args({10000 , 100000 , 4096 })
39
- ->Threads(4 )
40
- ->Threads(1 );
49
+ ->Apply(&default_alloc_fix_size);
41
50
42
51
UMF_BENCHMARK_TEMPLATE_DEFINE (alloc_benchmark, glibc_uniform,
43
52
uniform_alloc_size, glibc_malloc);
44
53
UMF_BENCHMARK_REGISTER_F (alloc_benchmark, glibc_uniform)
45
- ->Args({10000 , 0 , 8 , 64 * 1024 , 8 })
46
- ->Threads(4 )
47
- ->Threads(1 );
54
+ ->Apply(&default_alloc_uniform_size);
48
55
49
56
UMF_BENCHMARK_TEMPLATE_DEFINE (alloc_benchmark, os_provider, fixed_alloc_size,
50
57
provider_allocator<os_provider>);
51
58
UMF_BENCHMARK_REGISTER_F (alloc_benchmark, os_provider)
52
- ->Args({10000 , 0 , 4096 })
53
- ->Args({10000 , 100000 , 4096 })
54
- ->Threads(4 )
55
- ->Threads(1 );
59
+ ->Apply(&default_alloc_fix_size);
56
60
57
61
UMF_BENCHMARK_TEMPLATE_DEFINE (alloc_benchmark, proxy_pool, fixed_alloc_size,
58
62
pool_allocator<proxy_pool<os_provider>>);
59
63
60
64
UMF_BENCHMARK_REGISTER_F (alloc_benchmark, proxy_pool)
61
- ->Args({1000 , 0 , 4096 })
62
- ->Args({1000 , 100000 , 4096 })
63
- ->Threads(4 )
64
- ->Threads(1 );
65
+ ->Apply(&default_alloc_fix_size);
65
66
66
67
#ifdef UMF_POOL_DISJOINT_ENABLED
67
68
UMF_BENCHMARK_TEMPLATE_DEFINE (alloc_benchmark, disjoint_pool_fix,
68
69
fixed_alloc_size,
69
70
pool_allocator<disjoint_pool<os_provider>>);
70
71
UMF_BENCHMARK_REGISTER_F (alloc_benchmark, disjoint_pool_fix)
71
- ->Args({10000 , 0 , 4096 })
72
- ->Args({10000 , 100000 , 4096 })
73
- ->Threads(4 )
74
- ->Threads(1 );
72
+ ->Apply(&default_alloc_fix_size);
75
73
76
74
// TODO: debug why this crashes
77
75
/* UMF_BENCHMARK_TEMPLATE_DEFINE(alloc_benchmark, disjoint_pool_uniform,
78
76
uniform_alloc_size,
79
77
pool_allocator<disjoint_pool<os_provider>>);
80
78
UMF_BENCHMARK_REGISTER_F(alloc_benchmark, disjoint_pool_uniform)
81
- ->Args({10000, 0, 8, 64 * 1024, 8})
82
- // ->Threads(4)
83
- ->Threads(1);
79
+ ->Apply(&default_alloc_uniform_size);
84
80
*/
85
81
#endif
86
82
@@ -89,18 +85,13 @@ UMF_BENCHMARK_TEMPLATE_DEFINE(alloc_benchmark, jemalloc_pool_fix,
89
85
fixed_alloc_size,
90
86
pool_allocator<jemalloc_pool<os_provider>>);
91
87
UMF_BENCHMARK_REGISTER_F (alloc_benchmark, jemalloc_pool_fix)
92
- ->Args({10000 , 0 , 4096 })
93
- ->Args({10000 , 100000 , 4096 })
94
- ->Threads(4 )
95
- ->Threads(1 );
88
+ ->Apply(&default_alloc_fix_size);
96
89
97
90
UMF_BENCHMARK_TEMPLATE_DEFINE (alloc_benchmark, jemalloc_pool_uniform,
98
91
uniform_alloc_size,
99
92
pool_allocator<jemalloc_pool<os_provider>>);
100
93
UMF_BENCHMARK_REGISTER_F (alloc_benchmark, jemalloc_pool_uniform)
101
- ->Args({10000 , 0 , 8 , 64 * 1024 , 8 })
102
- ->Threads(4 )
103
- ->Threads(1 );
94
+ ->Apply(&default_alloc_uniform_size);
104
95
105
96
#endif
106
97
#ifdef UMF_POOL_SCALABLE_ENABLED
@@ -109,71 +100,67 @@ UMF_BENCHMARK_TEMPLATE_DEFINE(alloc_benchmark, scalable_pool_fix,
109
100
pool_allocator<scalable_pool<os_provider>>);
110
101
111
102
UMF_BENCHMARK_REGISTER_F (alloc_benchmark, scalable_pool_fix)
112
- ->Args({10000 , 0 , 4096 })
113
- ->Args({10000 , 100000 , 4096 })
114
- ->Threads(4 )
115
- ->Threads(1 );
103
+ ->Apply(&default_alloc_fix_size);
116
104
117
105
UMF_BENCHMARK_TEMPLATE_DEFINE (alloc_benchmark, scalable_pool_uniform,
118
106
uniform_alloc_size,
119
107
pool_allocator<scalable_pool<os_provider>>);
120
108
121
109
UMF_BENCHMARK_REGISTER_F (alloc_benchmark, scalable_pool_uniform)
122
- ->Args({10000 , 0 , 8 , 64 * 1024 , 8 })
123
- ->Threads(4 )
124
- ->Threads(1 );
110
+ ->Apply(&default_alloc_uniform_size);
125
111
#endif
126
112
// Multiple allocs/free
113
+ static void
114
+ default_multiple_alloc_fix_size (benchmark::internal::Benchmark *benchmark) {
115
+ benchmark->Args ({10000 , 4096 });
116
+ benchmark->Threads (4 );
117
+ benchmark->Threads (1 );
118
+ }
119
+
120
+ static void
121
+ default_multiple_alloc_uniform_size (benchmark::internal::Benchmark *benchmark) {
122
+ benchmark->Args ({10000 , 0 , 8 , 64 * 1024 , 8 });
123
+ benchmark->Threads (4 );
124
+ benchmark->Threads (1 );
125
+ }
127
126
128
127
UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark, glibc_fix,
129
128
fixed_alloc_size, glibc_malloc);
130
129
131
130
UMF_BENCHMARK_REGISTER_F (multiple_malloc_free_benchmark, glibc_fix)
132
- ->Args({10000 , 4096 })
133
- ->Threads(4 )
134
- ->Threads(1 );
131
+ ->Apply(&default_multiple_alloc_fix_size);
135
132
136
133
UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark, glibc_uniform,
137
134
uniform_alloc_size, glibc_malloc);
138
135
UMF_BENCHMARK_REGISTER_F (multiple_malloc_free_benchmark, glibc_uniform)
139
- ->Args({10000 , 8 , 64 * 1024 , 8 })
140
- ->Threads(4 )
141
- ->Threads(1 );
136
+ ->Apply(&default_multiple_alloc_uniform_size);
142
137
143
138
UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark, proxy_pool,
144
139
fixed_alloc_size,
145
140
pool_allocator<proxy_pool<os_provider>>);
146
141
147
142
UMF_BENCHMARK_REGISTER_F (multiple_malloc_free_benchmark, proxy_pool)
148
- ->Args({10000 , 4096 })
149
- ->Threads(4 )
150
- ->Threads(1 );
143
+ ->Apply(&default_multiple_alloc_fix_size);
151
144
152
145
UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark, os_provider,
153
146
fixed_alloc_size,
154
147
provider_allocator<os_provider>);
155
148
UMF_BENCHMARK_REGISTER_F (multiple_malloc_free_benchmark, os_provider)
156
- ->Args({10000 , 4096 })
157
- ->Threads(4 )
158
- ->Threads(1 );
149
+ ->Apply(&default_multiple_alloc_fix_size);
159
150
160
151
#ifdef UMF_POOL_DISJOINT_ENABLED
161
152
UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark, disjoint_pool_fix,
162
153
fixed_alloc_size,
163
154
pool_allocator<disjoint_pool<os_provider>>);
164
155
UMF_BENCHMARK_REGISTER_F (multiple_malloc_free_benchmark, disjoint_pool_fix)
165
- ->Args({10000 , 4096 })
166
- ->Threads(4 )
167
- ->Threads(1 );
156
+ ->Apply(&default_multiple_alloc_fix_size);
168
157
169
158
// TODO: debug why this crashes
170
159
/* UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
171
160
disjoint_pool_uniform, uniform_alloc_size,
172
161
pool_allocator<disjoint_pool<os_provider>>);
173
162
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark, disjoint_pool_uniform)
174
- ->Args({10000, 0, 8, 64 * 1024, 8})
175
- ->Threads(4)
176
- ->Threads(1);
163
+ ->Apply(&default_multiple_alloc_uniform_size);
177
164
*/
178
165
#endif
179
166
@@ -182,17 +169,13 @@ UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark, jemalloc_pool_fix,
182
169
fixed_alloc_size,
183
170
pool_allocator<jemalloc_pool<os_provider>>);
184
171
UMF_BENCHMARK_REGISTER_F (multiple_malloc_free_benchmark, jemalloc_pool_fix)
185
- ->Args({10000 , 4096 })
186
- ->Threads(4 )
187
- ->Threads(1 );
172
+ ->Apply(&default_multiple_alloc_fix_size);
188
173
189
174
UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark,
190
175
jemalloc_pool_uniform, uniform_alloc_size,
191
176
pool_allocator<jemalloc_pool<os_provider>>);
192
177
UMF_BENCHMARK_REGISTER_F (multiple_malloc_free_benchmark, jemalloc_pool_uniform)
193
- ->Args({1000 , 8 , 64 * 1024 , 8 })
194
- ->Threads(4 )
195
- ->Threads(1 );
178
+ ->Apply(&default_multiple_alloc_uniform_size);
196
179
197
180
#endif
198
181
@@ -202,18 +185,14 @@ UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark, scalable_pool_fix,
202
185
pool_allocator<scalable_pool<os_provider>>);
203
186
204
187
UMF_BENCHMARK_REGISTER_F (multiple_malloc_free_benchmark, scalable_pool_fix)
205
- ->Args({10000 , 4096 })
206
- ->Threads(4 )
207
- ->Threads(1 );
188
+ ->Apply(&default_multiple_alloc_fix_size);
208
189
209
190
UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark,
210
191
scalable_pool_uniform, uniform_alloc_size,
211
192
pool_allocator<scalable_pool<os_provider>>);
212
193
213
194
UMF_BENCHMARK_REGISTER_F (multiple_malloc_free_benchmark, scalable_pool_uniform)
214
- ->Args({10000 , 8 , 64 * 1024 , 8 })
215
- ->Threads(4 )
216
- ->Threads(1 );
195
+ ->Apply(&default_multiple_alloc_uniform_size);
217
196
218
197
#endif
219
198
BENCHMARK_MAIN ();
0 commit comments