Skip to content

Commit a26aa50

Browse files
committed
Add missing file
1 parent f842930 commit a26aa50

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

‎benchmark/map_binary_utils.hpp‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/****************************************************************************
2+
* Copyright (c) xsimd-algorithm contributors *
3+
* *
4+
* Distributed under the terms of the BSD 3-Clause License. *
5+
* *
6+
* The full license is in the file LICENSE, distributed with this software. *
7+
****************************************************************************/
8+
9+
#include <cstddef>
10+
#include <cstdint>
11+
#include <format>
12+
#include <string_view>
13+
#include <vector>
14+
15+
#include <benchmark/benchmark.h>
16+
17+
#include "bench_utils.hpp"
18+
#include "xsimd_algorithm/map.hpp"
19+
#include "xsimd_test_utils/utils.hpp"
20+
21+
namespace xsimd::bench
22+
{
23+
using xsimd::alignment_options;
24+
using xsimd::map_options;
25+
26+
template <typename Op, typename Alloc, typename Apply>
27+
void bench_binary(benchmark::State& state, Apply apply)
28+
{
29+
using lhs_t = typename Op::lhs_t;
30+
using rhs_t = typename Op::rhs_t;
31+
using output_t = typename Op::output_t;
32+
33+
auto const size = static_cast<std::size_t>(state.range(0));
34+
auto [lhs, rhs, output] = Op::template make_input_output<Alloc>(size);
35+
36+
for (auto _ : state)
37+
{
38+
apply(xsimd::test::as_span(lhs), xsimd::test::as_span(rhs), xsimd::test::as_span(output));
39+
benchmark::DoNotOptimize(output.data());
40+
benchmark::ClobberMemory();
41+
}
42+
43+
state.SetItemsProcessed(static_cast<std::int64_t>(state.iterations() * size));
44+
state.SetBytesProcessed(
45+
static_cast<std::int64_t>(state.iterations() * size * (sizeof(lhs_t) + sizeof(rhs_t) + sizeof(output_t))));
46+
}
47+
48+
template <
49+
typename Op,
50+
typename Alloc,
51+
typename Arch,
52+
alignment_options aligned = alignment_options {},
53+
map_options opts = map_options {}>
54+
void bench_map_binary(benchmark::State& state)
55+
{
56+
bench_binary<Op, Alloc>(
57+
state,
58+
[](auto lhs, auto rhs, auto out)
59+
{ Op::template range_apply_map_binary<aligned, opts, Arch>(lhs, rhs, out); });
60+
}
61+
62+
template <typename Op, typename Alloc>
63+
void bench_binary_scalar(benchmark::State& state)
64+
{
65+
bench_binary<Op, Alloc>(
66+
state,
67+
[](auto lhs, auto rhs, auto out)
68+
{ Op::range_apply_scalar(lhs, rhs, out); });
69+
}
70+
71+
template <typename Op, typename Arch, typename Bench>
72+
void register_binary_bench(
73+
std::string_view variant,
74+
Bench bench_fn,
75+
std::vector<std::int64_t> const& sizes = xsimd::bench::bench_sizes<typename Op::lhs_t>())
76+
{
77+
using lhs_t = typename Op::lhs_t;
78+
using rhs_t = typename Op::rhs_t;
79+
80+
auto* bench = benchmark::RegisterBenchmark(
81+
std::format(
82+
"{}/{}/{}_{}/{}",
83+
Arch::name(),
84+
Op::name,
85+
xsimd::bench::type_name<lhs_t>(),
86+
xsimd::bench::type_name<rhs_t>(),
87+
variant),
88+
bench_fn);
89+
for (auto const size : sizes)
90+
{
91+
bench->Arg(size);
92+
}
93+
}
94+
}

0 commit comments

Comments
 (0)