Merge pull request #1167 from redtide/benchmarks-demo-fixes

Benchmarks demo fixes
This commit is contained in:
redtide 2023-05-21 15:13:33 +02:00 committed by GitHub
commit cfba6fa16f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 140 additions and 77 deletions

View file

@ -9,13 +9,16 @@
#include <sndfile.hh> #include <sndfile.hh>
#define DR_FLAC_IMPLEMENTATION #define DR_FLAC_IMPLEMENTATION
#include "dr_flac.h" #include "dr_flac.h"
#include "ghc/filesystem.hpp" #include "ghc/fs_std.hpp"
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include <memory> #include <memory>
#ifndef NDEBUG #ifndef NDEBUG
#include <iostream> #include <iostream>
#endif #endif
// #include "libnyquist/Decoders.h" #if 0
#include "libnyquist/Decoders.h"
#endif
#include <unistd.h> // readlink
class FileFixture : public benchmark::Fixture { class FileFixture : public benchmark::Fixture {
public: public:
@ -23,9 +26,9 @@ public:
filePath1 = getPath() / "sample1.flac"; filePath1 = getPath() / "sample1.flac";
filePath2 = getPath() / "sample2.flac"; filePath2 = getPath() / "sample2.flac";
filePath3 = getPath() / "sample3.flac"; filePath3 = getPath() / "sample3.flac";
if ( !ghc::filesystem::exists(filePath1) if ( !fs::exists(filePath1)
|| !ghc::filesystem::exists(filePath2) || !fs::exists(filePath2)
|| !ghc::filesystem::exists(filePath3) ) { || !fs::exists(filePath3) ) {
#ifndef NDEBUG #ifndef NDEBUG
std::cerr << "Can't find path" << '\n'; std::cerr << "Can't find path" << '\n';
#endif #endif
@ -36,7 +39,7 @@ public:
void TearDown(const ::benchmark::State& /* state */) { void TearDown(const ::benchmark::State& /* state */) {
} }
ghc::filesystem::path getPath() fs::path getPath()
{ {
#ifdef __linux__ #ifdef __linux__
char buf[PATH_MAX + 1]; char buf[PATH_MAX + 1];
@ -45,18 +48,18 @@ public:
std::string str { buf }; std::string str { buf };
return str.substr(0, str.rfind('/')); return str.substr(0, str.rfind('/'));
#elif _WIN32 #elif _WIN32
return ghc::filesystem::current_path(); return fs::current_path();
#endif #endif
} }
std::unique_ptr<sfz::Buffer<float>> buffer; std::unique_ptr<sfz::Buffer<float>> buffer;
ghc::filesystem::path filePath1; fs::path filePath1;
ghc::filesystem::path filePath2; fs::path filePath2;
ghc::filesystem::path filePath3; fs::path filePath3;
}; };
#if defined(SFIZZ_USE_SNDFILE)
BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) { BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) {
for (auto _ : state) for (auto _ : state)
{ {
@ -65,6 +68,7 @@ BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) {
sndfile.readf(buffer->data(), sndfile.frames()); sndfile.readf(buffer->data(), sndfile.frames());
} }
} }
#endif
BENCHMARK_DEFINE_F(FileFixture, DrFlac)(benchmark::State& state) { BENCHMARK_DEFINE_F(FileFixture, DrFlac)(benchmark::State& state) {
for (auto _ : state) for (auto _ : state)
@ -75,17 +79,26 @@ BENCHMARK_DEFINE_F(FileFixture, DrFlac)(benchmark::State& state) {
} }
} }
// BENCHMARK_DEFINE_F(FileFixture, LibNyquist)(benchmark::State& state) { #if 0
// for (auto _ : state) BENCHMARK_DEFINE_F(FileFixture, LibNyquist)(benchmark::State& state) {
// { for (auto _ : state)
// nqr::AudioData data; {
// nqr::NyquistIO loader; nqr::AudioData data;
// loader.Load(&data, filePath3.string()); nqr::NyquistIO loader;
// benchmark::DoNotOptimize(data); loader.Load(&data, filePath3.string());
// } benchmark::DoNotOptimize(data);
// } }
}
#endif
#if defined(SFIZZ_USE_SNDFILE)
BENCHMARK_REGISTER_F(FileFixture, SndFile); BENCHMARK_REGISTER_F(FileFixture, SndFile);
#endif
BENCHMARK_REGISTER_F(FileFixture, DrFlac); BENCHMARK_REGISTER_F(FileFixture, DrFlac);
// BENCHMARK_REGISTER_F(FileFixture, LibNyquist);
#if 0
BENCHMARK_REGISTER_F(FileFixture, LibNyquist);
#endif
BENCHMARK_MAIN(); BENCHMARK_MAIN();

View file

@ -8,7 +8,7 @@
#include "Buffer.h" #include "Buffer.h"
#include <benchmark/benchmark.h> #include <benchmark/benchmark.h>
#include <sndfile.hh> #include <sndfile.hh>
#include "ghc/filesystem.hpp" #include "ghc/fs_std.hpp"
#define DR_WAV_IMPLEMENTATION #define DR_WAV_IMPLEMENTATION
#include "dr_wav.h" #include "dr_wav.h"
#include "AudioBuffer.h" #include "AudioBuffer.h"
@ -16,12 +16,13 @@
#ifndef NDEBUG #ifndef NDEBUG
#include <iostream> #include <iostream>
#endif #endif
#include <unistd.h> // readlink
class FileFixture : public benchmark::Fixture { class FileFixture : public benchmark::Fixture {
public: public:
void SetUp(const ::benchmark::State& /* state */) { void SetUp(const ::benchmark::State& /* state */) {
rootPath = getPath() / "sample1.wav"; rootPath = getPath() / "sample1.wav";
if (!ghc::filesystem::exists(rootPath)) { if (!fs::exists(rootPath)) {
#ifndef NDEBUG #ifndef NDEBUG
std::cerr << "Can't find path" << '\n'; std::cerr << "Can't find path" << '\n';
#endif #endif
@ -36,7 +37,7 @@ public:
void TearDown(const ::benchmark::State& /* state */) { void TearDown(const ::benchmark::State& /* state */) {
} }
ghc::filesystem::path getPath() fs::path getPath()
{ {
#ifdef __linux__ #ifdef __linux__
char buf[PATH_MAX + 1]; char buf[PATH_MAX + 1];
@ -45,13 +46,13 @@ public:
std::string str { buf }; std::string str { buf };
return str.substr(0, str.rfind('/')); return str.substr(0, str.rfind('/'));
#elif _WIN32 #elif _WIN32
return ghc::filesystem::current_path(); return fs::current_path();
#endif #endif
} }
std::unique_ptr<sfz::AudioBuffer<float>> output; std::unique_ptr<sfz::AudioBuffer<float>> output;
SndfileHandle sndfile; SndfileHandle sndfile;
ghc::filesystem::path rootPath; fs::path rootPath;
size_t numFrames; size_t numFrames;
}; };

View file

@ -8,7 +8,7 @@
#include "Buffer.h" #include "Buffer.h"
#include <benchmark/benchmark.h> #include <benchmark/benchmark.h>
#include <sndfile.hh> #include <sndfile.hh>
#include "ghc/filesystem.hpp" #include "ghc/fs_std.hpp"
#define DR_FLAC_IMPLEMENTATION #define DR_FLAC_IMPLEMENTATION
#include "dr_flac.h" #include "dr_flac.h"
#include "AudioBuffer.h" #include "AudioBuffer.h"
@ -16,12 +16,13 @@
#ifndef NDEBUG #ifndef NDEBUG
#include <iostream> #include <iostream>
#endif #endif
#include <unistd.h> // readlink
class FileFixture : public benchmark::Fixture { class FileFixture : public benchmark::Fixture {
public: public:
void SetUp(const ::benchmark::State& /* state */) { void SetUp(const ::benchmark::State& /* state */) {
rootPath = getPath() / "sample1.flac"; rootPath = getPath() / "sample1.flac";
if (!ghc::filesystem::exists(rootPath)) { if (!fs::exists(rootPath)) {
#ifndef NDEBUG #ifndef NDEBUG
std::cerr << "Can't find path" << '\n'; std::cerr << "Can't find path" << '\n';
#endif #endif
@ -36,7 +37,7 @@ public:
void TearDown(const ::benchmark::State& /* state */) { void TearDown(const ::benchmark::State& /* state */) {
} }
ghc::filesystem::path getPath() fs::path getPath()
{ {
#ifdef __linux__ #ifdef __linux__
char buf[PATH_MAX + 1]; char buf[PATH_MAX + 1];
@ -45,13 +46,13 @@ public:
std::string str { buf }; std::string str { buf };
return str.substr(0, str.rfind('/')); return str.substr(0, str.rfind('/'));
#elif _WIN32 #elif _WIN32
return ghc::filesystem::current_path(); return fs::current_path();
#endif #endif
} }
std::unique_ptr<sfz::AudioBuffer<float>> output; std::unique_ptr<sfz::AudioBuffer<float>> output;
SndfileHandle sndfile; SndfileHandle sndfile;
ghc::filesystem::path rootPath; fs::path rootPath;
size_t numFrames; size_t numFrames;
}; };

View file

@ -11,8 +11,10 @@
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include <samplerate.h> #include <samplerate.h>
#include <sndfile.hh> #include <sndfile.hh>
#include "ghc/filesystem.hpp" #include "ghc/fs_std.hpp"
#include "hiir/Upsampler2xFpu.h" #include "hiir/Upsampler2xFpu.h"
#include <unistd.h> // readlink
constexpr std::array<double, 12> coeffsStage2x { constexpr std::array<double, 12> coeffsStage2x {
0.036681502163648017, 0.036681502163648017,
0.13654762463195771, 0.13654762463195771,
@ -192,7 +194,7 @@ public:
{ {
const auto rootPath = getPath() / "sample1.wav"; const auto rootPath = getPath() / "sample1.wav";
if (!ghc::filesystem::exists(rootPath)) { if (!fs::exists(rootPath)) {
#ifndef NDEBUG #ifndef NDEBUG
std::cerr << "Can't find path" << '\n'; std::cerr << "Can't find path" << '\n';
#endif #endif
@ -210,7 +212,7 @@ public:
{ {
} }
ghc::filesystem::path getPath() fs::path getPath()
{ {
#ifdef __linux__ #ifdef __linux__
char buf[PATH_MAX + 1]; char buf[PATH_MAX + 1];
@ -219,7 +221,7 @@ public:
std::string str { buf }; std::string str { buf };
return str.substr(0, str.rfind('/')); return str.substr(0, str.rfind('/'));
#elif _WIN32 #elif _WIN32
return ghc::filesystem::current_path(); return fs::current_path();
#endif #endif
} }

View file

@ -3,17 +3,23 @@
// This code is part of the sfizz library and is licensed under a 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. // 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 // If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#include "Buffer.h" #include "Buffer.h"
#include <benchmark/benchmark.h> #include <benchmark/benchmark.h>
#if defined(SFIZZ_USE_SNDFILE)
#include <sndfile.hh> #include <sndfile.hh>
#endif
#define DR_WAV_IMPLEMENTATION #define DR_WAV_IMPLEMENTATION
#include "dr_wav.h" #include "dr_wav.h"
#include "ghc/filesystem.hpp" #include "ghc/fs_std.hpp"
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#if 0
#include "libnyquist/Decoders.h"
#endif
#ifndef NDEBUG #ifndef NDEBUG
#include <iostream> #include <iostream>
#endif #endif
// #include "libnyquist/Decoders.h" #include <unistd.h> // readlink
class FileFixture : public benchmark::Fixture { class FileFixture : public benchmark::Fixture {
public: public:
@ -21,9 +27,9 @@ public:
filePath1 = getPath() / "sample1.wav"; filePath1 = getPath() / "sample1.wav";
filePath2 = getPath() / "sample2.wav"; filePath2 = getPath() / "sample2.wav";
filePath3 = getPath() / "sample3.wav"; filePath3 = getPath() / "sample3.wav";
if ( !ghc::filesystem::exists(filePath1) if ( !fs::exists(filePath1)
|| !ghc::filesystem::exists(filePath2) || !fs::exists(filePath2)
|| !ghc::filesystem::exists(filePath3)) { || !fs::exists(filePath3)) {
#ifndef NDEBUG #ifndef NDEBUG
std::cerr << "Can't find path" << '\n'; std::cerr << "Can't find path" << '\n';
#endif #endif
@ -34,7 +40,7 @@ public:
void TearDown(const ::benchmark::State& /* state */) { void TearDown(const ::benchmark::State& /* state */) {
} }
ghc::filesystem::path getPath() fs::path getPath()
{ {
#ifdef __linux__ #ifdef __linux__
char buf[PATH_MAX + 1]; char buf[PATH_MAX + 1];
@ -43,18 +49,18 @@ public:
std::string str { buf }; std::string str { buf };
return str.substr(0, str.rfind('/')); return str.substr(0, str.rfind('/'));
#elif _WIN32 #elif _WIN32
return ghc::filesystem::current_path(); return fs::current_path();
#endif #endif
} }
std::unique_ptr<sfz::Buffer<float>> buffer; std::unique_ptr<sfz::Buffer<float>> buffer;
ghc::filesystem::path filePath1; fs::path filePath1;
ghc::filesystem::path filePath2; fs::path filePath2;
ghc::filesystem::path filePath3; fs::path filePath3;
}; };
#if defined(SFIZZ_USE_SNDFILE)
BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) { BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) {
for (auto _ : state) for (auto _ : state)
{ {
@ -63,6 +69,7 @@ BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) {
sndfile.readf(buffer->data(), sndfile.frames()); sndfile.readf(buffer->data(), sndfile.frames());
} }
} }
#endif
BENCHMARK_DEFINE_F(FileFixture, DrWav)(benchmark::State& state) { BENCHMARK_DEFINE_F(FileFixture, DrWav)(benchmark::State& state) {
for (auto _ : state) for (auto _ : state)
@ -79,17 +86,24 @@ BENCHMARK_DEFINE_F(FileFixture, DrWav)(benchmark::State& state) {
} }
} }
// BENCHMARK_DEFINE_F(FileFixture, LibNyquist)(benchmark::State& state) { #if 0
// for (auto _ : state) BENCHMARK_DEFINE_F(FileFixture, LibNyquist)(benchmark::State& state) {
// { for (auto _ : state)
// nqr::AudioData data; {
// nqr::NyquistIO loader; nqr::AudioData data;
// loader.Load(&data, filePath3.string()); nqr::NyquistIO loader;
// benchmark::DoNotOptimize(data); loader.Load(&data, filePath3.string());
// } benchmark::DoNotOptimize(data);
// } }
}
#endif
#if defined(SFIZZ_USE_SNDFILE)
BENCHMARK_REGISTER_F(FileFixture, SndFile); BENCHMARK_REGISTER_F(FileFixture, SndFile);
#endif
BENCHMARK_REGISTER_F(FileFixture, DrWav); BENCHMARK_REGISTER_F(FileFixture, DrWav);
// BENCHMARK_REGISTER_F(FileFixture, LibNyquist);
#if 0
BENCHMARK_REGISTER_F(FileFixture, LibNyquist);
#endif
BENCHMARK_MAIN(); BENCHMARK_MAIN();

View file

@ -18,7 +18,10 @@ sfizz_add_benchmark(bm_mathfuns BM_mathfuns.cpp)
sfizz_add_benchmark(bm_gain BM_gain.cpp) sfizz_add_benchmark(bm_gain BM_gain.cpp)
sfizz_add_benchmark(bm_divide BM_divide.cpp) sfizz_add_benchmark(bm_divide BM_divide.cpp)
sfizz_add_benchmark(bm_ramp BM_ramp.cpp) sfizz_add_benchmark(bm_ramp BM_ramp.cpp)
if(0) #FIXME
sfizz_add_benchmark(bm_ADSR BM_ADSR.cpp) sfizz_add_benchmark(bm_ADSR BM_ADSR.cpp)
endif()
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)
@ -39,13 +42,18 @@ sfizz_add_benchmark(bm_random BM_random.cpp)
sfizz_add_benchmark(bm_clamp BM_clamp.cpp) sfizz_add_benchmark(bm_clamp BM_clamp.cpp)
sfizz_add_benchmark(bm_allWithin BM_allWithin.cpp) sfizz_add_benchmark(bm_allWithin BM_allWithin.cpp)
if(0) #FIXME
sfizz_add_benchmark(bm_logger BM_logger.cpp) sfizz_add_benchmark(bm_logger BM_logger.cpp)
endif()
sfizz_add_benchmark(bm_smoothers BM_smoothers.cpp) sfizz_add_benchmark(bm_smoothers BM_smoothers.cpp)
sfizz_add_benchmark(bm_powerFollower BM_powerFollower.cpp) sfizz_add_benchmark(bm_powerFollower BM_powerFollower.cpp)
if(TARGET sfizz::samplerate) if(SFIZZ_USE_SNDFILE)
sfizz_add_benchmark(bm_resample BM_resample.cpp ${BENCHMARK_SIMD_SOURCES}) if(TARGET sfizz::samplerate)
target_link_libraries(bm_resample PRIVATE sfizz::samplerate sfizz::sndfile sfizz::hiir) sfizz_add_benchmark(bm_resample BM_resample.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_resample PRIVATE sfizz::samplerate sfizz::sndfile sfizz::hiir)
endif()
endif() endif()
sfizz_add_benchmark(bm_envelopes BM_envelopes.cpp) sfizz_add_benchmark(bm_envelopes BM_envelopes.cpp)
@ -56,13 +64,17 @@ target_link_libraries(bm_wavfile PRIVATE sfizz::sndfile)
sfizz_add_benchmark(bm_flacfile BM_flacfile.cpp) sfizz_add_benchmark(bm_flacfile BM_flacfile.cpp)
target_link_libraries(bm_flacfile PRIVATE sfizz::sndfile) target_link_libraries(bm_flacfile PRIVATE sfizz::sndfile)
sfizz_add_benchmark(bm_audioReaders BM_audioReaders.cpp ../src/sfizz/AudioReader.cpp) if(SFIZZ_USE_SNDFILE)
target_link_libraries(bm_audioReaders PRIVATE st_audiofile sfizz::sndfile) sfizz_add_benchmark(bm_audioReaders BM_audioReaders.cpp ../src/sfizz/AudioReader.cpp)
target_link_libraries(bm_audioReaders PRIVATE st_audiofile sfizz::sndfile)
endif()
sfizz_add_benchmark(bm_readChunk BM_readChunk.cpp) if(SFIZZ_USE_SNDFILE)
target_link_libraries(bm_readChunk PRIVATE sfizz::sndfile) sfizz_add_benchmark(bm_readChunk BM_readChunk.cpp)
sfizz_add_benchmark(bm_readChunkFlac BM_readChunkFlac.cpp) target_link_libraries(bm_readChunk PRIVATE sfizz::sndfile)
target_link_libraries(bm_readChunkFlac PRIVATE sfizz::sndfile) sfizz_add_benchmark(bm_readChunkFlac BM_readChunkFlac.cpp)
target_link_libraries(bm_readChunkFlac PRIVATE sfizz::sndfile)
endif()
sfizz_add_benchmark(bm_interpolators BM_interpolators.cpp) sfizz_add_benchmark(bm_interpolators BM_interpolators.cpp)

View file

@ -26,11 +26,22 @@ if(TARGET Qt5::Widgets)
set_target_properties(sfizz_demo_stretch_tuning PROPERTIES AUTOUIC ON) set_target_properties(sfizz_demo_stretch_tuning PROPERTIES AUTOUIC ON)
endif() endif()
add_executable(eq_apply EQ.cpp) if(SFIZZ_USE_SNDFILE)
target_link_libraries(eq_apply PRIVATE sfizz::internal sfizz::sndfile sfizz::cxxopts sfizz::filesystem) add_executable(eq_apply EQ.cpp)
target_link_libraries(eq_apply PRIVATE
add_executable(filter_apply Filter.cpp) sfizz::cxxopts
target_link_libraries(filter_apply PRIVATE sfizz::internal sfizz::sndfile sfizz::cxxopts sfizz::filesystem) sfizz::filesystem
sfizz::internal
sfizz::sndfile
)
add_executable(filter_apply Filter.cpp)
target_link_libraries(filter_apply PRIVATE
sfizz::cxxopts
sfizz::filesystem
sfizz::internal
sfizz::sndfile
)
endif()
add_executable(sfizz_plot_curve PlotCurve.cpp) add_executable(sfizz_plot_curve PlotCurve.cpp)
target_link_libraries(sfizz_plot_curve PRIVATE sfizz::internal) target_link_libraries(sfizz_plot_curve PRIVATE sfizz::internal)
@ -38,11 +49,19 @@ target_link_libraries(sfizz_plot_curve PRIVATE sfizz::internal)
add_executable(sfizz_plot_wavetables PlotWavetables.cpp) add_executable(sfizz_plot_wavetables PlotWavetables.cpp)
target_link_libraries(sfizz_plot_wavetables PRIVATE sfizz::internal) target_link_libraries(sfizz_plot_wavetables PRIVATE sfizz::internal)
add_executable(sfizz_plot_lfo PlotLFO.cpp) if(SFIZZ_USE_SNDFILE)
target_link_libraries(sfizz_plot_lfo PRIVATE sfizz::internal sfizz::sndfile sfizz::cxxopts) add_executable(sfizz_plot_lfo PlotLFO.cpp)
target_link_libraries(sfizz_plot_lfo PRIVATE
add_executable(sfizz_file_instrument FileInstrument.cpp) sfizz::cxxopts
target_link_libraries(sfizz_file_instrument PRIVATE sfizz::internal sfizz::sndfile) sfizz::internal
sfizz::sndfile
)
add_executable(sfizz_file_instrument FileInstrument.cpp)
target_link_libraries(sfizz_file_instrument PRIVATE
sfizz::internal
sfizz::sndfile
)
endif()
add_executable(sfizz_file_wavetable FileWavetable.cpp) add_executable(sfizz_file_wavetable FileWavetable.cpp)
target_link_libraries(sfizz_file_wavetable PRIVATE sfizz::internal) target_link_libraries(sfizz_file_wavetable PRIVATE sfizz::internal)

View file

@ -36,8 +36,8 @@ int main(int argc, char *argv[])
sfz::WavetableInfo wt {}; sfz::WavetableInfo wt {};
sfz::FileMetadataReader reader; sfz::FileMetadataReader reader(path);
if (!reader.open(path)) { if (!reader.open()) {
fprintf(stderr, "Cannot open file\n"); fprintf(stderr, "Cannot open file\n");
return 1; return 1;
} }

View file

@ -92,6 +92,7 @@ int main(int argc, char* argv[])
sfzPath = argv[1]; sfzPath = argv[1];
} }
// FIXME: OptionException was replaced by some cxxopts::exceptions::???
catch (cxxopts::OptionException& ex) { catch (cxxopts::OptionException& ex) {
std::cerr << ex.what() << "\n"; std::cerr << ex.what() << "\n";
return 1; return 1;