sfizz/benchmarks/BM_envelopes.cpp

110 lines
3.6 KiB
C++
Raw Normal View History

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
2020-01-04 17:38:51 +01:00
#include "SIMDHelpers.h"
2019-12-13 09:34:36 +01:00
#include <benchmark/benchmark.h>
#include <random>
#include <numeric>
#include <vector>
#include <cmath>
#include <iostream>
2020-04-07 00:50:38 +02:00
#include "ModifierHelpers.h"
2019-12-13 09:34:36 +01:00
#include "absl/types/span.h"
class EnvelopeFixture : public benchmark::Fixture {
public:
void SetUp(const ::benchmark::State& state)
{
input = std::vector<float>(state.range(0));
output = std::vector<float>(state.range(0));
std::generate(input.begin(), input.end(), [&]() { return dist(gen); });
2020-05-31 12:40:18 +02:00
sfz::cumsum<float>(input, absl::MakeSpan(input));
2019-12-13 09:34:36 +01:00
}
void TearDown(const ::benchmark::State& /* state */)
2019-12-13 09:34:36 +01:00
{
}
std::random_device rd { };
std::mt19937 gen { rd() };
2020-03-31 09:53:46 +02:00
std::uniform_real_distribution<float> dist { 2, 30 };
2019-12-13 09:34:36 +01:00
std::vector<float> input;
std::vector<float> output;
};
BENCHMARK_DEFINE_F(EnvelopeFixture, Linear)(benchmark::State& state) {
for (auto _ : state)
{
2020-03-31 09:53:46 +02:00
sfz::EventVector events {
2020-03-31 10:46:12 +02:00
{ 0, 0.0f },
{ static_cast<int>(state.range(0) - 1), dist(gen) }
2020-03-31 09:53:46 +02:00
};
2020-03-31 18:48:18 +02:00
sfz::linearEnvelope(events, absl::MakeSpan(output), [](float x) { return x; });
}
}
BENCHMARK_DEFINE_F(EnvelopeFixture, LinearNoEvent) (benchmark::State& state) {
for (auto _ : state) {
2020-03-31 18:48:18 +02:00
sfz::EventVector events {
{ 0, dist(gen) }
};
sfz::linearEnvelope(events, absl::MakeSpan(output), [](float x) { return x; });
2019-12-13 09:34:36 +01:00
}
}
BENCHMARK_DEFINE_F(EnvelopeFixture, LinearQuantized)(benchmark::State& state) {
for (auto _ : state)
{
2020-03-31 09:53:46 +02:00
sfz::EventVector events {
2020-03-31 10:46:12 +02:00
{ 0, 0.0f },
{ static_cast<int>(state.range(0) - 1), dist(gen) }
2020-03-31 09:53:46 +02:00
};
2020-03-31 18:48:18 +02:00
sfz::linearEnvelope(
2020-03-31 10:46:12 +02:00
events, absl::MakeSpan(output), [](float x) { return x; }, 0.5);
2019-12-13 09:34:36 +01:00
}
}
BENCHMARK_DEFINE_F(EnvelopeFixture, Multiplicative)(benchmark::State& state) {
for (auto _ : state)
{
2020-03-31 09:53:46 +02:00
sfz::EventVector events {
2020-03-31 10:46:12 +02:00
{ 0, 1.0f },
{ static_cast<int>(state.range(0) - 1), dist(gen) }
2020-03-31 09:53:46 +02:00
};
2020-03-31 18:48:18 +02:00
sfz::multiplicativeEnvelope(events, absl::MakeSpan(output), [](float x) { return x; });
}
}
BENCHMARK_DEFINE_F(EnvelopeFixture, MultiplicativeNoEvent) (benchmark::State& state) {
for (auto _ : state) {
2020-03-31 18:48:18 +02:00
sfz::EventVector events {
{ 0, dist(gen) }
};
sfz::multiplicativeEnvelope(events, absl::MakeSpan(output), [](float x) { return x; });
2019-12-13 09:34:36 +01:00
}
}
BENCHMARK_DEFINE_F(EnvelopeFixture, MultiplicativeQuantized)(benchmark::State& state) {
for (auto _ : state)
{
2020-03-31 09:53:46 +02:00
sfz::EventVector events {
2020-03-31 10:46:12 +02:00
{ 0, 1.0f },
{ static_cast<int>(state.range(0) - 1), dist(gen) }
2020-03-31 09:53:46 +02:00
};
2020-03-31 18:48:18 +02:00
sfz::multiplicativeEnvelope(
2020-03-31 10:46:12 +02:00
events, absl::MakeSpan(output), [](float x) { return x; }, 2.0f);
2019-12-13 09:34:36 +01:00
}
}
BENCHMARK_REGISTER_F(EnvelopeFixture, Linear)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
2020-03-31 18:48:18 +02:00
BENCHMARK_REGISTER_F(EnvelopeFixture, LinearNoEvent)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
2019-12-13 09:34:36 +01:00
BENCHMARK_REGISTER_F(EnvelopeFixture, LinearQuantized)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_REGISTER_F(EnvelopeFixture, Multiplicative)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
2020-03-31 18:48:18 +02:00
BENCHMARK_REGISTER_F(EnvelopeFixture, MultiplicativeNoEvent)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
2019-12-13 09:34:36 +01:00
BENCHMARK_REGISTER_F(EnvelopeFixture, MultiplicativeQuantized)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
2020-01-04 17:38:51 +01:00
BENCHMARK_MAIN();