Skip to content

Commit de4672b

Browse files
committed
Add --bench-profile option to SConstruct
- Introduce a new SCons option `--bench-profile` to select benchmark profile: small, medium, or large. - SCons now sets the appropriate preprocessor define (`ROC_BENCHMARK_PROFILE_SMALL`, `_MEDIUM`, or `_LARGE`) based on the selected profile. - Update benchmark sources to use these defines to control dataset sizes, thread counts, and iteration counts for various benchmarks. - Default values are chosen if no profile is specified. - Refactor hardcoded benchmark parameters in `bench_mpsc_queue.cpp`, `bench_task_queue_contention.cpp`, and `bench_pipeline_loop_contention.cpp` to use the new profile-based configuration. - Included `bench_profile.h` to select default ROC_BENCHMARK_PROFILE_* for specific arch.
1 parent 44d7d7d commit de4672b

File tree

6 files changed

+92
-5
lines changed

6 files changed

+92
-5
lines changed

SConstruct

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ AddOption('--override-targets',
287287
" pass a comma-separated list of target names,"
288288
" e.g. 'pc,posix,posix_ext,gnu,libuv,openfec,...'"))
289289

290+
AddOption('--bench-profile',
291+
dest='bench_profile',
292+
action='store',
293+
type='string',
294+
help=('set benchmark profile: small, medium, or large'))
295+
290296
# configure even in dry run mode
291297
SCons.SConf.dryrun = 0
292298

@@ -914,6 +920,23 @@ if meta.platform in ['windows']:
914920
('_WIN32_WINNT', '0x0601'),
915921
])
916922

923+
# set roc_bench_profile
924+
# controls the size of the benchmark data set
925+
# it can be set to 'small', 'medium', or 'large'
926+
# if not set, default is chosen based on architecture
927+
bench_profile = GetOption('bench_profile')
928+
if bench_profile:
929+
profile = bench_profile.lower()
930+
if profile == 'small':
931+
env.AppendUnique(CPPDEFINES=['ROC_BENCHMARK_PROFILE_SMALL'])
932+
elif profile == 'medium':
933+
env.AppendUnique(CPPDEFINES=['ROC_BENCHMARK_PROFILE_MEDIUM'])
934+
elif profile == 'large':
935+
env.AppendUnique(CPPDEFINES=['ROC_BENCHMARK_PROFILE_LARGE'])
936+
else:
937+
env.Die("unknown --bench-profile '{}', expected one of: small, medium, large",
938+
bench_profile)
939+
917940
# env will hold settings common to all code
918941
# subenvs will hold settings specific to particular parts of code
919942
subenv_names = 'internal_modules public_libs examples tools tests generated_code'.split()

src/tests/bench_main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "roc_core/crash_handler.h"
1010
#include "roc_core/heap_arena.h"
1111
#include "roc_core/log.h"
12+
#include "bench_profile.h"
1213

1314
#include <benchmark/benchmark.h>
1415

src/tests/bench_profile.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2025 Roc Streaming authors
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+
*/
8+
9+
#ifndef ROC_BENCH_PROFILE_H_
10+
#define ROC_BENCH_PROFILE_H_
11+
12+
#include "roc_core/cpu_traits.h"
13+
14+
#if !defined(ROC_BENCHMARK_PROFILE_LARGE) && \
15+
!defined(ROC_BENCHMARK_PROFILE_MEDIUM) && \
16+
!defined(ROC_BENCHMARK_PROFILE_SMALL)
17+
18+
#ifndef ROC_CPU_FAMILY
19+
#error "ROC_CPU_FAMILY is not defined. Please define it to use ROC_BENCHMARK_PROFILE_* macros"
20+
#endif
21+
22+
// LARGE profile: High-performance workstation-class architectures
23+
#if ROC_CPU_FAMILY == ROC_CPU_FAMILY_X86_64 || \
24+
ROC_CPU_FAMILY == ROC_CPU_FAMILY_PPC64 || \
25+
ROC_CPU_FAMILY == ROC_CPU_FAMILY_S390X
26+
#define ROC_BENCHMARK_PROFILE_LARGE
27+
// MEDIUM profile: Powerful SBCs and capable architectures
28+
#elif ROC_CPU_FAMILY == ROC_CPU_FAMILY_GENERIC || \
29+
ROC_CPU_FAMILY == ROC_CPU_FAMILY_X86 || \
30+
ROC_CPU_FAMILY == ROC_CPU_FAMILY_PPC || \
31+
ROC_CPU_FAMILY == ROC_CPU_FAMILY_S390 || \
32+
ROC_CPU_FAMILY == ROC_CPU_FAMILY_LOONGARCH64 || \
33+
ROC_CPU_FAMILY == ROC_CPU_FAMILY_AARCH64 || \
34+
ROC_CPU_FAMILY == ROC_CPU_FAMILY_MIPS64 || \
35+
ROC_CPU_FAMILY == ROC_CPU_FAMILY_RISCV64
36+
#define ROC_BENCHMARK_PROFILE_MEDIUM
37+
#else
38+
// SMALL profile: Weak CPUs, embedded systems, and specialized processors
39+
#define ROC_BENCHMARK_PROFILE_SMALL
40+
#endif
41+
42+
#endif // !defined(ROC_BENCHMARK_PROFILE_...)
43+
44+
#endif // ROC_BENCH_PROFILE_H_

src/tests/roc_core/bench_mpsc_queue.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@ namespace roc {
1616
namespace core {
1717
namespace {
1818

19-
enum { BatchSize = 10000, NumIterations = 5000000, NumThreads = 16 };
19+
enum {
20+
BatchSize = 10000,
21+
#ifdef ROC_BENCHMARK_PROFILE_LARGE
22+
NumIterations = 5000000,
23+
NumThreads = 16
24+
#else
25+
NumIterations = 500000,
26+
NumThreads = 4
27+
#endif
28+
};
2029

2130
#if defined(ROC_BENCHMARK_USE_ACCESSORS)
2231
inline int get_thread_index(const benchmark::State& state) {
@@ -150,8 +159,10 @@ BENCHMARK_REGISTER_F(BM_MpscQueue, TryPopFront)
150159
->Arg(1)
151160
->Arg(2)
152161
->Arg(4)
162+
#ifdef ROC_BENCHMARK_PROFILE_LARGE
153163
->Arg(8)
154164
->Arg(16)
165+
#endif
155166
->Iterations(NumIterations)
156167
->Unit(benchmark::kMicrosecond);
157168

@@ -184,8 +195,10 @@ BENCHMARK_REGISTER_F(BM_MpscQueue, PopFront)
184195
->Arg(1)
185196
->Arg(2)
186197
->Arg(4)
198+
#ifdef ROC_BENCHMARK_PROFILE_LARGE
187199
->Arg(8)
188200
->Arg(16)
201+
#endif
189202
->Iterations(NumIterations)
190203
->Unit(benchmark::kMicrosecond);
191204

src/tests/roc_ctl/bench_task_queue_contention.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ namespace ctl {
1717
namespace {
1818

1919
enum {
20-
#ifdef __aarch64__
21-
NumScheduleIterations = 200000,
22-
#else
20+
#ifdef ROC_BENCHMARK_PROFILE_LARGE
2321
NumScheduleIterations = 2000000,
24-
#endif
2522
NumScheduleAfterIterations = 20000,
2623
NumThreads = 8,
24+
#else
25+
NumScheduleIterations = 200000,
26+
NumScheduleAfterIterations = 5000,
27+
NumThreads = 4,
28+
#endif
2729
BatchSize = 1000
2830
};
2931

src/tests/roc_pipeline/bench_pipeline_loop_contention.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ namespace {
3131
enum {
3232
SampleRate = 1000000, // 1 sample = 1 us (for convenience)
3333
Chans = 0x1,
34+
#ifdef ROC_BENCHMARK_PROFILE_LARGE
3435
NumThreads = 16,
36+
#else
37+
NumThreads = 4,
38+
#endif
3539
NumIterations = 1000000,
3640
BatchSize = 10000,
3741
FrameBufSize = 100

0 commit comments

Comments
 (0)