diff --git a/benchmarks/BM_ADSR.cpp b/benchmarks/BM_ADSR.cpp index 32f227f5..c74735b6 100644 --- a/benchmarks/BM_ADSR.cpp +++ b/benchmarks/BM_ADSR.cpp @@ -11,45 +11,61 @@ #include #include -constexpr int fixedAmount { 12 }; -constexpr int envelopeSize { 2 << 16 }; -constexpr int attack = static_cast(envelopeSize / 4) - fixedAmount; -constexpr int decay = attack; -constexpr int release = attack; -constexpr int releaseTime = envelopeSize - static_cast(envelopeSize / 4); +constexpr int fixedAmount{12}; +constexpr float sampleRate{100.0f}; +constexpr int envelopeSize{2 << 16}; +constexpr float attack = static_cast(static_cast(envelopeSize / 4) - fixedAmount) / sampleRate; +constexpr float decay = attack; +constexpr float release = attack; +constexpr float releaseTime = envelopeSize - static_cast(envelopeSize / 4); -// Explicitely instantiate class -#include "ADSREnvelope.cpp" -template class sfz::ADSREnvelope; +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)); + } -static void Point(benchmark::State& state) { - std::vector output(state.range(0)); + void TearDown(const ::benchmark::State &state[[maybe_unused]]) + { + } + + sfz::MidiState midiState; + sfz::Region region{midiState}; sfz::ADSREnvelope envelope; + std::vector output; +}; + +BENCHMARK_DEFINE_F(EnvelopeFixture, Scalar)(benchmark::State& state) +{ for (auto _ : state) { - envelope.reset(attack, release, 1.0, fixedAmount, decay, fixedAmount); + envelope.reset(region, midiState, 0, 0, sampleRate); envelope.startRelease(releaseTime); - for(int offset = 0; offset < envelopeSize; offset += static_cast(state.range(0))) + for (int offset = 0; offset < envelopeSize; offset += static_cast(state.range(0))) for (auto& out: output) out = envelope.getNextValue(); benchmark::DoNotOptimize(output); } - state.counters["Per block"] = benchmark::Counter(envelopeSize / static_cast(state.range(0)), benchmark::Counter::kIsRate); + state.counters["Blocks"] = benchmark::Counter(envelopeSize / static_cast(state.range(0)), benchmark::Counter::kIsIterationInvariantRate); } -static void Block(benchmark::State& state) { - std::vector output(state.range(0)); - sfz::ADSREnvelope envelope; +BENCHMARK_DEFINE_F(EnvelopeFixture, Block)(benchmark::State& state) +{ for (auto _ : state) { - envelope.reset(attack, release, 1.0, fixedAmount, decay, fixedAmount); + envelope.reset(region, midiState, 0, 0, sampleRate); envelope.startRelease(releaseTime); - for(int offset = 0; offset < envelopeSize; offset += static_cast(state.range(0))) + for (int offset = 0; offset < envelopeSize; offset += static_cast(state.range(0))) envelope.getBlock(absl::MakeSpan(output)); benchmark::DoNotOptimize(output); } - state.counters["Per block"] = benchmark::Counter(envelopeSize / static_cast(state.range(0)), benchmark::Counter::kIsRate); + state.counters["Blocks"] = benchmark::Counter(envelopeSize / static_cast(state.range(0)), benchmark::Counter::kIsIterationInvariantRate); } -BENCHMARK(Point)->RangeMultiplier(2)->Range((2<<6), (2<<11)); -BENCHMARK(Block)->RangeMultiplier(2)->Range((2<<6), (2<<11)); +BENCHMARK_REGISTER_F(EnvelopeFixture, Scalar)->RangeMultiplier(2)->Range((2 << 6), (2 << 11)); +BENCHMARK_REGISTER_F(EnvelopeFixture, Block)->RangeMultiplier(2)->Range((2 << 6), (2 << 11)); BENCHMARK_MAIN(); diff --git a/benchmarks/BM_envelopes.cpp b/benchmarks/BM_envelopes.cpp index 2a1f7221..63b9582d 100644 --- a/benchmarks/BM_envelopes.cpp +++ b/benchmarks/BM_envelopes.cpp @@ -13,8 +13,6 @@ #include "EventEnvelopes.h" #include "absl/types/span.h" -#include "FloatEnvelopes.cpp" - class EnvelopeFixture : public benchmark::Fixture { public: void SetUp(const ::benchmark::State& state) diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index a73c12b5..dd7bfb65 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -42,6 +42,8 @@ sfizz_add_benchmark(bm_looping BM_looping.cpp) sfizz_add_benchmark(bm_saturating BM_saturating.cpp) sfizz_add_benchmark(bm_ramp BM_ramp.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_multiplyAdd BM_multiplyAdd.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) 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) target_link_libraries(bm_wavfile PRIVATE sfizz-sndfile)