55 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66 *
77 */
8-
98#include " benchmark.hpp"
9+ #include < benchmark/benchmark.h>
1010
1111#define UMF_BENCHMARK_TEMPLATE_DEFINE (BaseClass, Method, ...) \
1212 BENCHMARK_TEMPLATE_DEFINE_F (BaseClass, Method, __VA_ARGS__) \
1818
1919#define UMF_BENCHMARK_REGISTER_F (BaseClass, Method ) \
2020 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)
2923
3024// Benchmarks scenarios:
3125
3226// The benchmark arguments specified in Args() are, in order:
3327// benchmark arguments, allocator arguments, size generator arguments.
3428// The exact meaning of each argument depends on the benchmark, allocator, and size components used.
3529// 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+
3648UMF_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);
4150
4251UMF_BENCHMARK_TEMPLATE_DEFINE (alloc_benchmark, glibc_uniform,
4352 uniform_alloc_size, glibc_malloc);
4453UMF_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);
4855
4956UMF_BENCHMARK_TEMPLATE_DEFINE (alloc_benchmark, os_provider, fixed_alloc_size,
5057 provider_allocator<os_provider>);
5158UMF_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);
5660
5761UMF_BENCHMARK_TEMPLATE_DEFINE (alloc_benchmark, proxy_pool, fixed_alloc_size,
5862 pool_allocator<proxy_pool<os_provider>>);
5963
6064UMF_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);
6566
6667#ifdef UMF_POOL_DISJOINT_ENABLED
6768UMF_BENCHMARK_TEMPLATE_DEFINE (alloc_benchmark, disjoint_pool_fix,
6869 fixed_alloc_size,
6970 pool_allocator<disjoint_pool<os_provider>>);
7071UMF_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);
7573
7674// TODO: debug why this crashes
7775/* UMF_BENCHMARK_TEMPLATE_DEFINE(alloc_benchmark, disjoint_pool_uniform,
7876 uniform_alloc_size,
7977 pool_allocator<disjoint_pool<os_provider>>);
8078UMF_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);
8480*/
8581#endif
8682
@@ -89,18 +85,13 @@ UMF_BENCHMARK_TEMPLATE_DEFINE(alloc_benchmark, jemalloc_pool_fix,
8985 fixed_alloc_size,
9086 pool_allocator<jemalloc_pool<os_provider>>);
9187UMF_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);
9689
9790UMF_BENCHMARK_TEMPLATE_DEFINE (alloc_benchmark, jemalloc_pool_uniform,
9891 uniform_alloc_size,
9992 pool_allocator<jemalloc_pool<os_provider>>);
10093UMF_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);
10495
10596#endif
10697#ifdef UMF_POOL_SCALABLE_ENABLED
@@ -109,71 +100,67 @@ UMF_BENCHMARK_TEMPLATE_DEFINE(alloc_benchmark, scalable_pool_fix,
109100 pool_allocator<scalable_pool<os_provider>>);
110101
111102UMF_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);
116104
117105UMF_BENCHMARK_TEMPLATE_DEFINE (alloc_benchmark, scalable_pool_uniform,
118106 uniform_alloc_size,
119107 pool_allocator<scalable_pool<os_provider>>);
120108
121109UMF_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);
125111#endif
126112// 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+ }
127126
128127UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark, glibc_fix,
129128 fixed_alloc_size, glibc_malloc);
130129
131130UMF_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);
135132
136133UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark, glibc_uniform,
137134 uniform_alloc_size, glibc_malloc);
138135UMF_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);
142137
143138UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark, proxy_pool,
144139 fixed_alloc_size,
145140 pool_allocator<proxy_pool<os_provider>>);
146141
147142UMF_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);
151144
152145UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark, os_provider,
153146 fixed_alloc_size,
154147 provider_allocator<os_provider>);
155148UMF_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);
159150
160151#ifdef UMF_POOL_DISJOINT_ENABLED
161152UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark, disjoint_pool_fix,
162153 fixed_alloc_size,
163154 pool_allocator<disjoint_pool<os_provider>>);
164155UMF_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);
168157
169158// TODO: debug why this crashes
170159/* UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
171160 disjoint_pool_uniform, uniform_alloc_size,
172161 pool_allocator<disjoint_pool<os_provider>>);
173162UMF_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);
177164*/
178165#endif
179166
@@ -182,17 +169,13 @@ UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark, jemalloc_pool_fix,
182169 fixed_alloc_size,
183170 pool_allocator<jemalloc_pool<os_provider>>);
184171UMF_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);
188173
189174UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark,
190175 jemalloc_pool_uniform, uniform_alloc_size,
191176 pool_allocator<jemalloc_pool<os_provider>>);
192177UMF_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);
196179
197180#endif
198181
@@ -202,18 +185,14 @@ UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark, scalable_pool_fix,
202185 pool_allocator<scalable_pool<os_provider>>);
203186
204187UMF_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);
208189
209190UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark,
210191 scalable_pool_uniform, uniform_alloc_size,
211192 pool_allocator<scalable_pool<os_provider>>);
212193
213194UMF_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);
217196
218197#endif
219198BENCHMARK_MAIN ();
0 commit comments