Corrected benchmarks
This commit is contained in:
parent
4e9e286213
commit
507831ae47
3 changed files with 41 additions and 25 deletions
|
|
@ -11,45 +11,61 @@
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
|
||||||
constexpr int fixedAmount { 12 };
|
constexpr int fixedAmount{12};
|
||||||
constexpr int envelopeSize { 2 << 16 };
|
constexpr float sampleRate{100.0f};
|
||||||
constexpr int attack = static_cast<int>(envelopeSize / 4) - fixedAmount;
|
constexpr int envelopeSize{2 << 16};
|
||||||
constexpr int decay = attack;
|
constexpr float attack = static_cast<float>(static_cast<int>(envelopeSize / 4) - fixedAmount) / sampleRate;
|
||||||
constexpr int release = attack;
|
constexpr float decay = attack;
|
||||||
constexpr int releaseTime = envelopeSize - static_cast<int>(envelopeSize / 4);
|
constexpr float release = attack;
|
||||||
|
constexpr float releaseTime = envelopeSize - static_cast<int>(envelopeSize / 4);
|
||||||
|
|
||||||
// Explicitely instantiate class
|
class EnvelopeFixture : public benchmark::Fixture
|
||||||
#include "ADSREnvelope.cpp"
|
{
|
||||||
template class sfz::ADSREnvelope<float>;
|
public:
|
||||||
|
void SetUp(const ::benchmark::State &state)
|
||||||
|
{
|
||||||
|
region.amplitudeEG.attack = attack;
|
||||||
|
region.amplitudeEG.release = release;
|
||||||
|
region.amplitudeEG.decay = decay;
|
||||||
|
output.resize(state.range(0));
|
||||||
|
}
|
||||||
|
|
||||||
static void Point(benchmark::State& state) {
|
void TearDown(const ::benchmark::State &state[[maybe_unused]])
|
||||||
std::vector<float> output(state.range(0));
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
sfz::MidiState midiState;
|
||||||
|
sfz::Region region{midiState};
|
||||||
sfz::ADSREnvelope<float> envelope;
|
sfz::ADSREnvelope<float> envelope;
|
||||||
|
std::vector<float> output;
|
||||||
|
};
|
||||||
|
|
||||||
|
BENCHMARK_DEFINE_F(EnvelopeFixture, Scalar)(benchmark::State& state)
|
||||||
|
{
|
||||||
for (auto _ : state) {
|
for (auto _ : state) {
|
||||||
envelope.reset(attack, release, 1.0, fixedAmount, decay, fixedAmount);
|
envelope.reset(region, midiState, 0, 0, sampleRate);
|
||||||
envelope.startRelease(releaseTime);
|
envelope.startRelease(releaseTime);
|
||||||
for(int offset = 0; offset < envelopeSize; offset += static_cast<int>(state.range(0)))
|
for (int offset = 0; offset < envelopeSize; offset += static_cast<int>(state.range(0)))
|
||||||
for (auto& out: output)
|
for (auto& out: output)
|
||||||
out = envelope.getNextValue();
|
out = envelope.getNextValue();
|
||||||
benchmark::DoNotOptimize(output);
|
benchmark::DoNotOptimize(output);
|
||||||
}
|
}
|
||||||
state.counters["Per block"] = benchmark::Counter(envelopeSize / static_cast<double>(state.range(0)), benchmark::Counter::kIsRate);
|
state.counters["Blocks"] = benchmark::Counter(envelopeSize / static_cast<double>(state.range(0)), benchmark::Counter::kIsIterationInvariantRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Block(benchmark::State& state) {
|
BENCHMARK_DEFINE_F(EnvelopeFixture, Block)(benchmark::State& state)
|
||||||
std::vector<float> output(state.range(0));
|
{
|
||||||
sfz::ADSREnvelope<float> envelope;
|
|
||||||
for (auto _ : state) {
|
for (auto _ : state) {
|
||||||
envelope.reset(attack, release, 1.0, fixedAmount, decay, fixedAmount);
|
envelope.reset(region, midiState, 0, 0, sampleRate);
|
||||||
envelope.startRelease(releaseTime);
|
envelope.startRelease(releaseTime);
|
||||||
for(int offset = 0; offset < envelopeSize; offset += static_cast<int>(state.range(0)))
|
for (int offset = 0; offset < envelopeSize; offset += static_cast<int>(state.range(0)))
|
||||||
envelope.getBlock(absl::MakeSpan(output));
|
envelope.getBlock(absl::MakeSpan(output));
|
||||||
benchmark::DoNotOptimize(output);
|
benchmark::DoNotOptimize(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
state.counters["Per block"] = benchmark::Counter(envelopeSize / static_cast<double>(state.range(0)), benchmark::Counter::kIsRate);
|
state.counters["Blocks"] = benchmark::Counter(envelopeSize / static_cast<double>(state.range(0)), benchmark::Counter::kIsIterationInvariantRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
BENCHMARK(Point)->RangeMultiplier(2)->Range((2<<6), (2<<11));
|
BENCHMARK_REGISTER_F(EnvelopeFixture, Scalar)->RangeMultiplier(2)->Range((2 << 6), (2 << 11));
|
||||||
BENCHMARK(Block)->RangeMultiplier(2)->Range((2<<6), (2<<11));
|
BENCHMARK_REGISTER_F(EnvelopeFixture, Block)->RangeMultiplier(2)->Range((2 << 6), (2 << 11));
|
||||||
BENCHMARK_MAIN();
|
BENCHMARK_MAIN();
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,6 @@
|
||||||
#include "EventEnvelopes.h"
|
#include "EventEnvelopes.h"
|
||||||
#include "absl/types/span.h"
|
#include "absl/types/span.h"
|
||||||
|
|
||||||
#include "FloatEnvelopes.cpp"
|
|
||||||
|
|
||||||
class EnvelopeFixture : public benchmark::Fixture {
|
class EnvelopeFixture : public benchmark::Fixture {
|
||||||
public:
|
public:
|
||||||
void SetUp(const ::benchmark::State& state)
|
void SetUp(const ::benchmark::State& state)
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,8 @@ sfizz_add_benchmark(bm_looping BM_looping.cpp)
|
||||||
sfizz_add_benchmark(bm_saturating BM_saturating.cpp)
|
sfizz_add_benchmark(bm_saturating BM_saturating.cpp)
|
||||||
sfizz_add_benchmark(bm_ramp BM_ramp.cpp)
|
sfizz_add_benchmark(bm_ramp BM_ramp.cpp)
|
||||||
sfizz_add_benchmark(bm_ADSR BM_ADSR.cpp)
|
sfizz_add_benchmark(bm_ADSR BM_ADSR.cpp)
|
||||||
|
target_link_libraries(bm_ADSR PRIVATE sfizz::sfizz)
|
||||||
|
|
||||||
sfizz_add_benchmark(bm_add BM_add.cpp)
|
sfizz_add_benchmark(bm_add BM_add.cpp)
|
||||||
sfizz_add_benchmark(bm_multiplyAdd BM_multiplyAdd.cpp)
|
sfizz_add_benchmark(bm_multiplyAdd BM_multiplyAdd.cpp)
|
||||||
sfizz_add_benchmark(bm_subtract BM_subtract.cpp)
|
sfizz_add_benchmark(bm_subtract BM_subtract.cpp)
|
||||||
|
|
@ -60,7 +62,7 @@ if (TARGET sfizz-samplerate)
|
||||||
target_link_libraries(bm_resample PRIVATE sfizz-samplerate sfizz-sndfile)
|
target_link_libraries(bm_resample PRIVATE sfizz-samplerate sfizz-sndfile)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
sfizz_add_benchmark(bm_envelopes BM_envelopes.cpp)
|
sfizz_add_benchmark(bm_envelopes BM_envelopes.cpp ../src/sfizz/MidiState.cpp ../src/sfizz/FloatEnvelopes.cpp)
|
||||||
|
|
||||||
sfizz_add_benchmark(bm_wavfile BM_wavfile.cpp)
|
sfizz_add_benchmark(bm_wavfile BM_wavfile.cpp)
|
||||||
target_link_libraries(bm_wavfile PRIVATE sfizz-sndfile)
|
target_link_libraries(bm_wavfile PRIVATE sfizz-sndfile)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue