sfizz/benchmarks/BM_ADSR.cpp

58 lines
1.9 KiB
C++
Raw Permalink 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
2019-08-30 00:49:58 +02:00
2020-01-04 17:38:51 +01:00
#include "Config.h"
#include "ADSREnvelope.h"
2020-01-04 17:38:51 +01:00
#include <benchmark/benchmark.h>
#include <algorithm>
#include <random>
#include <numeric>
2020-02-19 12:25:03 +01:00
constexpr int fixedAmount{12};
constexpr float sampleRate{100.0f};
constexpr int envelopeSize{2 << 16};
constexpr float attack = static_cast<float>(static_cast<int>(envelopeSize / 4) - fixedAmount) / sampleRate;
constexpr float decay = attack;
constexpr float release = attack;
constexpr float releaseTime = envelopeSize - static_cast<int>(envelopeSize / 4);
class EnvelopeFixture : public benchmark::Fixture
{
public:
void SetUp(const ::benchmark::State &state)
{
region.amplitudeEG.attack = attack;
region.amplitudeEG.release = release;
region.amplitudeEG.decay = decay;
output.resize(state.range(0));
}
void TearDown(const ::benchmark::State& /* state */)
2020-02-19 12:25:03 +01:00
{
}
sfz::MidiState midiState;
2021-03-25 21:46:21 +01:00
sfz::Region region{0};
2021-02-01 10:30:17 +01:00
sfz::ADSREnvelope envelope;
2020-02-19 12:25:03 +01:00
std::vector<float> output;
};
BENCHMARK_DEFINE_F(EnvelopeFixture, Block)(benchmark::State& state)
{
for (auto _ : state) {
envelope.reset(region.amplitudeEG, region, midiState, 0, 0, sampleRate);
envelope.startRelease(releaseTime);
2020-02-19 12:25:03 +01:00
for (int offset = 0; offset < envelopeSize; offset += static_cast<int>(state.range(0)))
envelope.getBlock(absl::MakeSpan(output));
benchmark::DoNotOptimize(output);
}
2020-02-19 12:25:03 +01:00
state.counters["Blocks"] = benchmark::Counter(envelopeSize / static_cast<double>(state.range(0)), benchmark::Counter::kIsIterationInvariantRate);
}
2020-02-19 12:25:03 +01:00
BENCHMARK_REGISTER_F(EnvelopeFixture, Block)->RangeMultiplier(2)->Range((2 << 6), (2 << 11));
2020-01-04 17:38:51 +01:00
BENCHMARK_MAIN();