2020-01-25 10:04:31 +01:00
|
|
|
// SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
2020-01-25 13:13:07 +01:00
|
|
|
// This code is part of the sfizz library and is licensed under a BSD 2-clause
|
|
|
|
|
// license. You should have receive a LICENSE.md file along with the code.
|
|
|
|
|
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
2019-09-07 16:28:33 +02:00
|
|
|
|
2020-01-04 17:38:51 +01:00
|
|
|
#include "SIMDHelpers.h"
|
2019-09-07 16:28:33 +02:00
|
|
|
#include <benchmark/benchmark.h>
|
|
|
|
|
#include <random>
|
|
|
|
|
#include <numeric>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <iostream>
|
2019-11-23 18:58:51 +01:00
|
|
|
#include "Config.h"
|
2020-02-10 19:36:04 +01:00
|
|
|
#include "ScopedFTZ.h"
|
2019-09-07 16:28:33 +02:00
|
|
|
#include "absl/types/span.h"
|
|
|
|
|
|
|
|
|
|
class PanArray : public benchmark::Fixture {
|
|
|
|
|
public:
|
|
|
|
|
void SetUp(const ::benchmark::State& state) {
|
|
|
|
|
std::random_device rd { };
|
|
|
|
|
std::mt19937 gen { rd() };
|
2020-01-04 17:38:51 +01:00
|
|
|
std::uniform_real_distribution<float> dist { 0.001f, 1.0f };
|
2019-09-07 16:28:33 +02:00
|
|
|
pan = std::vector<float>(state.range(0));
|
|
|
|
|
left = std::vector<float>(state.range(0));
|
|
|
|
|
right = std::vector<float>(state.range(0));
|
|
|
|
|
std::generate(pan.begin(), pan.end(), [&]() { return dist(gen); });
|
|
|
|
|
std::generate(right.begin(), right.end(), [&]() { return dist(gen); });
|
|
|
|
|
std::generate(left.begin(), left.end(), [&]() { return dist(gen); });
|
|
|
|
|
temp1 = std::vector<float>(state.range(0));
|
|
|
|
|
temp2 = std::vector<float>(state.range(0));
|
|
|
|
|
span1 = absl::MakeSpan(temp1);
|
|
|
|
|
span2 = absl::MakeSpan(temp2);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 00:18:18 +01:00
|
|
|
void TearDown(const ::benchmark::State& /* state */) {
|
2019-09-07 16:28:33 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<float> pan;
|
|
|
|
|
std::vector<float> left;
|
|
|
|
|
std::vector<float> right;
|
|
|
|
|
std::vector<float> temp1;
|
|
|
|
|
std::vector<float> temp2;
|
|
|
|
|
absl::Span<float> span1;
|
|
|
|
|
absl::Span<float> span2;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BENCHMARK_DEFINE_F(PanArray, Scalar)(benchmark::State& state) {
|
2020-02-10 19:36:04 +01:00
|
|
|
ScopedFTZ ftz;
|
2019-09-07 16:28:33 +02:00
|
|
|
for (auto _ : state)
|
|
|
|
|
{
|
2019-09-25 23:48:52 +02:00
|
|
|
sfz::pan<float, false>(pan, absl::MakeSpan(left), absl::MakeSpan(right));
|
2019-09-07 16:28:33 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BENCHMARK_DEFINE_F(PanArray, SIMD)(benchmark::State& state) {
|
2020-02-10 19:36:04 +01:00
|
|
|
ScopedFTZ ftz;
|
2019-09-07 16:28:33 +02:00
|
|
|
for (auto _ : state)
|
|
|
|
|
{
|
2019-09-25 23:48:52 +02:00
|
|
|
sfz::pan<float, true>(pan, absl::MakeSpan(left), absl::MakeSpan(right));
|
2019-09-07 16:28:33 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BENCHMARK_DEFINE_F(PanArray, BlockOps)(benchmark::State& state) {
|
2020-02-10 19:36:04 +01:00
|
|
|
ScopedFTZ ftz;
|
2019-09-07 16:28:33 +02:00
|
|
|
for (auto _ : state)
|
|
|
|
|
{
|
2019-09-25 23:48:52 +02:00
|
|
|
sfz::fill<float>(span2, 1.0f);
|
|
|
|
|
sfz::add<float>(span1, span2);
|
2020-03-11 01:11:25 +01:00
|
|
|
sfz::applyGain<float>(piFour<float>(), span2);
|
2019-09-25 23:48:52 +02:00
|
|
|
sfz::cos<float>(span2, span1);
|
|
|
|
|
sfz::sin<float>(span2, span2);
|
|
|
|
|
sfz::applyGain<float>(span1, absl::MakeSpan(left));
|
|
|
|
|
sfz::applyGain<float>(span2, absl::MakeSpan(right));
|
2019-09-07 16:28:33 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BENCHMARK_REGISTER_F(PanArray, Scalar)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
|
|
|
|
|
BENCHMARK_REGISTER_F(PanArray, SIMD)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
|
|
|
|
|
BENCHMARK_REGISTER_F(PanArray, BlockOps)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
|
2020-01-04 17:38:51 +01:00
|
|
|
BENCHMARK_MAIN();
|