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