Add benchmark
This commit is contained in:
parent
cb144ad42f
commit
4c3db6c2c8
2 changed files with 62 additions and 0 deletions
60
benchmarks/BM_powerFollower.cpp
Normal file
60
benchmarks/BM_powerFollower.cpp
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
// SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
||||||
|
#include "PowerFollower.h"
|
||||||
|
#include "AudioBuffer.h"
|
||||||
|
#include "Config.h"
|
||||||
|
#include <benchmark/benchmark.h>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
class PowerFollowerFixture : public benchmark::Fixture {
|
||||||
|
public:
|
||||||
|
PowerFollowerFixture()
|
||||||
|
{
|
||||||
|
inputSignal_ = sfz::AudioBuffer<float>(2, numFrames);
|
||||||
|
auto leftSignal = inputSignal_.getSpan(0);
|
||||||
|
auto rightSignal = inputSignal_.getSpan(1);
|
||||||
|
float phase = 0;
|
||||||
|
for (size_t i = 0; i < numFrames; ++i) {
|
||||||
|
constexpr float k2pi = 2.0 * M_PI;
|
||||||
|
leftSignal[i] = std::sin(k2pi * phase);
|
||||||
|
rightSignal[i] = std::cos(k2pi * phase);
|
||||||
|
phase += 440.0f / sfz::config::defaultSampleRate;
|
||||||
|
phase -= static_cast<int>(phase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetUp(const ::benchmark::State& state)
|
||||||
|
{
|
||||||
|
auto blockSize = static_cast<size_t>(state.range(0));
|
||||||
|
follower_.setSampleRate(sfz::config::defaultSampleRate);
|
||||||
|
follower_.setSamplesPerBlock(blockSize);
|
||||||
|
follower_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TearDown(const ::benchmark::State& /* state */)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr size_t numFrames = 65536;
|
||||||
|
sfz::PowerFollower follower_;
|
||||||
|
sfz::AudioBuffer<float> inputSignal_;
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr size_t PowerFollowerFixture::numFrames;
|
||||||
|
|
||||||
|
BENCHMARK_DEFINE_F(PowerFollowerFixture, Follower) (benchmark::State& state)
|
||||||
|
{
|
||||||
|
sfz::AudioSpan<float> inputSignal(inputSignal_);
|
||||||
|
for (auto _ : state) {
|
||||||
|
auto& follower = follower_;
|
||||||
|
auto blockSize = static_cast<size_t>(state.range(0));
|
||||||
|
for (size_t i = 0; i < numFrames; i += blockSize)
|
||||||
|
follower.process(inputSignal.subspan(i, blockSize));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCHMARK_REGISTER_F(PowerFollowerFixture, Follower)->RangeMultiplier(2)->Range(1 << 5, 1 << 12);
|
||||||
|
|
@ -66,6 +66,8 @@ sfizz_add_benchmark(bm_logger BM_logger.cpp)
|
||||||
target_link_libraries(bm_logger PRIVATE sfizz::sfizz)
|
target_link_libraries(bm_logger PRIVATE sfizz::sfizz)
|
||||||
sfizz_add_benchmark(bm_smoothers BM_smoothers.cpp)
|
sfizz_add_benchmark(bm_smoothers BM_smoothers.cpp)
|
||||||
target_link_libraries(bm_smoothers PRIVATE sfizz::sfizz)
|
target_link_libraries(bm_smoothers PRIVATE sfizz::sfizz)
|
||||||
|
sfizz_add_benchmark(bm_powerFollower BM_powerFollower.cpp)
|
||||||
|
target_link_libraries(bm_powerFollower PRIVATE sfizz::sfizz)
|
||||||
|
|
||||||
if (TARGET sfizz-samplerate)
|
if (TARGET sfizz-samplerate)
|
||||||
sfizz_add_benchmark(bm_resample BM_resample.cpp ${BENCHMARK_SIMD_SOURCES})
|
sfizz_add_benchmark(bm_resample BM_resample.cpp ${BENCHMARK_SIMD_SOURCES})
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue