88 #include < concepts>
99 #include < cstddef>
1010 #include < cstdint>
11- #include < format>
1211 #include < functional>
1312 #include < new>
1413 #include < ranges>
1514 #include < span>
1615 #include < type_traits>
17- #include < utility>
1816 #include < vector>
1917#else
2018import std;
@@ -63,29 +61,30 @@ auto fold_result_is_correct(fold_accum_t<T> result, fold_accum_t<T> expect) -> b
6361}
6462
6563template <fold_data_mode Data, typename T, typename Fn>
66- void run_fold_input (benchmark::State &state, Fn &&fn) {
67-
64+ void run_fold_input (benchmark::State &state, std::int64_t threads, Fn fn) {
6865 auto n = static_cast <std::size_t >(state.range (0 ));
6966 auto expect = expected_fold_result<T>(n);
7067
71- auto bench = [&](auto range) -> void {
72- for (auto _ : state) {
73- if (auto result = std::invoke (fn, range); !fold_result_is_correct<T>(result, expect)) {
74- state.SkipWithError (std::format (" incorrect result: {} != {}" , result, expect));
75- break ;
76- }
77- }
68+ auto run = [&](auto const &range) -> void {
69+ lf_bench::bench (state, threads, expect, fold_result_is_correct<T>, [&]() -> fold_accum_t <T> {
70+ return std::invoke (fn, range);
71+ });
7872 };
7973
8074 if constexpr (Data == fold_data_mode::memory) {
81- bench (make_fold_range<T>(n) | std::ranges::to<std::vector<T>>());
75+ run (make_fold_range<T>(n) | std::ranges::to<std::vector<T>>());
8276 } else {
83- bench (make_fold_range<T>(n));
77+ run (make_fold_range<T>(n));
8478 }
8579
8680 state.SetItemsProcessed (state.iterations () * static_cast <std::int64_t >(n));
8781}
8882
83+ template <fold_data_mode Data, typename T, typename Fn>
84+ void run_fold_input (benchmark::State &state, Fn fn) {
85+ run_fold_input<Data, T>(state, lf_bench::no_threads, fn);
86+ }
87+
8988// Use alias for shorted names.
9089inline constexpr auto memory = fold_data_mode::memory;
9190inline constexpr auto lazy = fold_data_mode::lazy;
@@ -98,13 +97,13 @@ inline constexpr auto async_proj = fold_projection_mode::async;
9897using int32 = std::int32_t ;
9998using float32 = float ;
10099
101- #define LF_FOLD_BENCH_SIZES_SMALL (bench_fn, category, name, ...) \
100+ #define LF_FOLD_BENCH_SIZES_SMALL (bench_fn, category, name, ...) \
102101 BENCH_ONE (bench_fn, category, name, test, fold __VA_OPT__ (, ) __VA_ARGS__) \
103102 BENCH_ONE(bench_fn, category, name, base, fold_1024 __VA_OPT__ (, ) __VA_ARGS__) \
104- BENCH_ONE(bench_fn, category, name, base, fold_1024_sq __VA_OPT__ (, ) __VA_ARGS__) \
103+ BENCH_ONE(bench_fn, category, name, base, fold_1024_sq __VA_OPT__ (, ) __VA_ARGS__)
105104
106105#define LF_FOLD_BENCH_SIZES (bench_fn, category, name, ...) \
107- LF_FOLD_BENCH_SIZES_SMALL (bench_fn, category, name __VA_OPT__ (, ) __VA_ARGS__) \
106+ LF_FOLD_BENCH_SIZES_SMALL (bench_fn, category, name __VA_OPT__ (, ) __VA_ARGS__) \
108107 BENCH_ONE(bench_fn, category, name, base, fold_1024_cu __VA_OPT__ (, ) __VA_ARGS__)
109108
110109#define LF_FOLD_BENCH_SIZES_MT (bench_fn, category, name, ...) \
0 commit comments