Add the benchmark for string resonator
This commit is contained in:
parent
319554321b
commit
86e3c2232f
2 changed files with 113 additions and 0 deletions
103
benchmarks/BM_stringResonator.cpp
Normal file
103
benchmarks/BM_stringResonator.cpp
Normal file
|
|
@ -0,0 +1,103 @@
|
||||||
|
// 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 "Macros.h"
|
||||||
|
#include "ScopedFTZ.h"
|
||||||
|
#include "MathHelpers.h"
|
||||||
|
#include "SIMDConfig.h"
|
||||||
|
#include "effects/impl/ResonantArray.h"
|
||||||
|
#include "effects/impl/ResonantArraySSE.h"
|
||||||
|
#include "effects/impl/ResonantArrayAVX.h"
|
||||||
|
#include <benchmark/benchmark.h>
|
||||||
|
#include <random>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class AddArray : public benchmark::Fixture {
|
||||||
|
public:
|
||||||
|
void SetUp(const ::benchmark::State& state) {
|
||||||
|
std::random_device rd { };
|
||||||
|
std::mt19937 gen { rd() };
|
||||||
|
|
||||||
|
numStrings = state.range(0);
|
||||||
|
pitches.resize(numStrings);
|
||||||
|
bandwidths.resize(numStrings);
|
||||||
|
feedbacks.resize(numStrings);
|
||||||
|
gains.resize(numStrings);
|
||||||
|
|
||||||
|
std::generate(pitches.begin(), pitches.end(), [&]() {
|
||||||
|
std::uniform_int_distribution<> dist {0, 127};
|
||||||
|
return midiNoteFrequency(dist(gen));
|
||||||
|
});
|
||||||
|
|
||||||
|
std::fill(bandwidths.begin(), bandwidths.end(), 1.0f);
|
||||||
|
std::fill(feedbacks.begin(), feedbacks.end(), std::exp(-6.91 / (50e-3 * sampleRate)));
|
||||||
|
std::fill(gains.begin(), gains.end(), 1e-3f);
|
||||||
|
|
||||||
|
input.resize(numFrames);
|
||||||
|
output.resize(numFrames);
|
||||||
|
|
||||||
|
std::generate(input.begin(), input.end(), [&]() {
|
||||||
|
std::uniform_real_distribution<> dist {-1, 1};
|
||||||
|
return dist(gen);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void TearDown(const ::benchmark::State& state) {
|
||||||
|
UNUSED(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr float sampleRate = 44100;
|
||||||
|
static constexpr unsigned numFrames = sampleRate * 5.0;
|
||||||
|
std::vector<float> input;
|
||||||
|
std::vector<float> output;
|
||||||
|
unsigned numStrings = 0;
|
||||||
|
std::vector<float> pitches;
|
||||||
|
std::vector<float> bandwidths;
|
||||||
|
std::vector<float> feedbacks;
|
||||||
|
std::vector<float> gains;
|
||||||
|
};
|
||||||
|
|
||||||
|
BENCHMARK_DEFINE_F(AddArray, StringResonator_Scalar)(benchmark::State& state) {
|
||||||
|
ScopedFTZ ftz;
|
||||||
|
sfz::fx::ResonantArrayScalar resonator;
|
||||||
|
resonator.setup(sampleRate, numStrings, pitches.data(), bandwidths.data(), feedbacks.data(), gains.data());
|
||||||
|
resonator.setSamplesPerBlock(numFrames);
|
||||||
|
for (auto _ : state)
|
||||||
|
{
|
||||||
|
resonator.process(input.data(), output.data(), numFrames);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if SFIZZ_CPU_FAMILY_X86_64 || SFIZZ_CPU_FAMILY_I386
|
||||||
|
BENCHMARK_DEFINE_F(AddArray, StringResonator_SSE)(benchmark::State& state) {
|
||||||
|
ScopedFTZ ftz;
|
||||||
|
sfz::fx::ResonantArraySSE resonator;
|
||||||
|
resonator.setup(sampleRate, numStrings, pitches.data(), bandwidths.data(), feedbacks.data(), gains.data());
|
||||||
|
resonator.setSamplesPerBlock(numFrames);
|
||||||
|
for (auto _ : state)
|
||||||
|
{
|
||||||
|
resonator.process(input.data(), output.data(), numFrames);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCHMARK_DEFINE_F(AddArray, StringResonator_AVX)(benchmark::State& state) {
|
||||||
|
ScopedFTZ ftz;
|
||||||
|
sfz::fx::ResonantArrayAVX resonator;
|
||||||
|
resonator.setup(sampleRate, numStrings, pitches.data(), bandwidths.data(), feedbacks.data(), gains.data());
|
||||||
|
resonator.setSamplesPerBlock(numFrames);
|
||||||
|
for (auto _ : state)
|
||||||
|
{
|
||||||
|
resonator.process(input.data(), output.data(), numFrames);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
BENCHMARK_REGISTER_F(AddArray, StringResonator_Scalar)->RangeMultiplier(4)->Range(1, 128);
|
||||||
|
#if SFIZZ_CPU_FAMILY_X86_64 || SFIZZ_CPU_FAMILY_I386
|
||||||
|
BENCHMARK_REGISTER_F(AddArray, StringResonator_SSE)->RangeMultiplier(4)->Range(1, 128);
|
||||||
|
BENCHMARK_REGISTER_F(AddArray, StringResonator_AVX)->RangeMultiplier(4)->Range(1, 128);
|
||||||
|
#endif
|
||||||
|
BENCHMARK_MAIN();
|
||||||
|
|
@ -93,6 +93,15 @@ target_link_libraries(bm_filterModulation PRIVATE sfizz-sndfile)
|
||||||
sfizz_add_benchmark(bm_filterStereoMono BM_filterStereoMono.cpp ../src/sfizz/SfzFilter.cpp)
|
sfizz_add_benchmark(bm_filterStereoMono BM_filterStereoMono.cpp ../src/sfizz/SfzFilter.cpp)
|
||||||
target_link_libraries(bm_filterStereoMono PRIVATE sfizz-sndfile)
|
target_link_libraries(bm_filterStereoMono PRIVATE sfizz-sndfile)
|
||||||
|
|
||||||
|
sfizz_add_benchmark(bm_stringResonator BM_stringResonator.cpp
|
||||||
|
../src/sfizz/effects/impl/ResonantArray.cpp
|
||||||
|
../src/sfizz/effects/impl/ResonantArraySSE.cpp
|
||||||
|
../src/sfizz/effects/impl/ResonantArrayAVX.cpp
|
||||||
|
../src/sfizz/effects/impl/ResonantString.cpp
|
||||||
|
../src/sfizz/effects/impl/ResonantStringSSE.cpp
|
||||||
|
../src/sfizz/effects/impl/ResonantStringAVX.cpp)
|
||||||
|
target_link_libraries(bm_stringResonator PRIVATE sfizz-sndfile)
|
||||||
|
|
||||||
add_custom_target(sfizz_benchmarks)
|
add_custom_target(sfizz_benchmarks)
|
||||||
add_dependencies(sfizz_benchmarks
|
add_dependencies(sfizz_benchmarks
|
||||||
bm_opf_high_vs_low
|
bm_opf_high_vs_low
|
||||||
|
|
@ -126,6 +135,7 @@ add_dependencies(sfizz_benchmarks
|
||||||
bm_flacfile
|
bm_flacfile
|
||||||
bm_filterModulation
|
bm_filterModulation
|
||||||
bm_filterStereoMono
|
bm_filterStereoMono
|
||||||
|
bm_stringResonator
|
||||||
)
|
)
|
||||||
|
|
||||||
if (TARGET bm_resample)
|
if (TARGET bm_resample)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue