11/*
2- * Copyright (C) 2024 Intel Corporation
2+ * Copyright (C) 2024-2025 Intel Corporation
33 *
44 * Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
55 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66 *
77 */
88
9+ #include < benchmark/benchmark.h>
10+
911#include " benchmark.hpp"
1012
1113#define UMF_BENCHMARK_TEMPLATE_DEFINE (BaseClass, Method, ...) \
1820
1921#define UMF_BENCHMARK_REGISTER_F (BaseClass, Method ) \
2022 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)
2925
3026// Benchmarks scenarios:
3127
3228// The benchmark arguments specified in Args() are, in order:
3329// benchmark arguments, allocator arguments, size generator arguments.
3430// The exact meaning of each argument depends on the benchmark, allocator, and size components used.
3531// 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+
3650UMF_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);
4152
4253UMF_BENCHMARK_TEMPLATE_DEFINE (alloc_benchmark, glibc_uniform,
4354 uniform_alloc_size, glibc_malloc);
4455UMF_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);
4857
4958UMF_BENCHMARK_TEMPLATE_DEFINE (alloc_benchmark, os_provider, fixed_alloc_size,
5059 provider_allocator<os_provider>);
5160UMF_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);
5662
5763UMF_BENCHMARK_TEMPLATE_DEFINE (alloc_benchmark, proxy_pool, fixed_alloc_size,
5864 pool_allocator<proxy_pool<os_provider>>);
5965
6066UMF_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);
6568
6669#ifdef UMF_POOL_DISJOINT_ENABLED
6770UMF_BENCHMARK_TEMPLATE_DEFINE (alloc_benchmark, disjoint_pool_fix,
6871 fixed_alloc_size,
6972 pool_allocator<disjoint_pool<os_provider>>);
7073UMF_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);
7575
7676// TODO: debug why this crashes
7777/* UMF_BENCHMARK_TEMPLATE_DEFINE(alloc_benchmark, disjoint_pool_uniform,
7878 uniform_alloc_size,
7979 pool_allocator<disjoint_pool<os_provider>>);
8080UMF_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);
8482*/
8583#endif
8684
@@ -89,18 +87,13 @@ UMF_BENCHMARK_TEMPLATE_DEFINE(alloc_benchmark, jemalloc_pool_fix,
8987 fixed_alloc_size,
9088 pool_allocator<jemalloc_pool<os_provider>>);
9189UMF_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);
9691
9792UMF_BENCHMARK_TEMPLATE_DEFINE (alloc_benchmark, jemalloc_pool_uniform,
9893 uniform_alloc_size,
9994 pool_allocator<jemalloc_pool<os_provider>>);
10095UMF_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);
10497
10598#endif
10699#ifdef UMF_POOL_SCALABLE_ENABLED
@@ -109,71 +102,67 @@ UMF_BENCHMARK_TEMPLATE_DEFINE(alloc_benchmark, scalable_pool_fix,
109102 pool_allocator<scalable_pool<os_provider>>);
110103
111104UMF_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);
116106
117107UMF_BENCHMARK_TEMPLATE_DEFINE (alloc_benchmark, scalable_pool_uniform,
118108 uniform_alloc_size,
119109 pool_allocator<scalable_pool<os_provider>>);
120110
121111UMF_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);
125113#endif
126114// 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+ }
127128
128129UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark, glibc_fix,
129130 fixed_alloc_size, glibc_malloc);
130131
131132UMF_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);
135134
136135UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark, glibc_uniform,
137136 uniform_alloc_size, glibc_malloc);
138137UMF_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);
142139
143140UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark, proxy_pool,
144141 fixed_alloc_size,
145142 pool_allocator<proxy_pool<os_provider>>);
146143
147144UMF_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);
151146
152147UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark, os_provider,
153148 fixed_alloc_size,
154149 provider_allocator<os_provider>);
155150UMF_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);
159152
160153#ifdef UMF_POOL_DISJOINT_ENABLED
161154UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark, disjoint_pool_fix,
162155 fixed_alloc_size,
163156 pool_allocator<disjoint_pool<os_provider>>);
164157UMF_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);
168159
169160// TODO: debug why this crashes
170161/* UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
171162 disjoint_pool_uniform, uniform_alloc_size,
172163 pool_allocator<disjoint_pool<os_provider>>);
173164UMF_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);
177166*/
178167#endif
179168
@@ -182,17 +171,13 @@ UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark, jemalloc_pool_fix,
182171 fixed_alloc_size,
183172 pool_allocator<jemalloc_pool<os_provider>>);
184173UMF_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);
188175
189176UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark,
190177 jemalloc_pool_uniform, uniform_alloc_size,
191178 pool_allocator<jemalloc_pool<os_provider>>);
192179UMF_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);
196181
197182#endif
198183
@@ -202,18 +187,14 @@ UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark, scalable_pool_fix,
202187 pool_allocator<scalable_pool<os_provider>>);
203188
204189UMF_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);
208191
209192UMF_BENCHMARK_TEMPLATE_DEFINE (multiple_malloc_free_benchmark,
210193 scalable_pool_uniform, uniform_alloc_size,
211194 pool_allocator<scalable_pool<os_provider>>);
212195
213196UMF_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);
217198
218199#endif
219200BENCHMARK_MAIN ();
0 commit comments