From 56b0f4d957440e0c9ecc72604ac0d37b7fbdc5a6 Mon Sep 17 00:00:00 2001 From: redtide Date: Sun, 21 May 2023 14:26:48 +0200 Subject: [PATCH] Temporary fixes for benchmarks, see #1148 --- benchmarks/BM_flacfile.cpp | 55 +++++++++++++++++++------------- benchmarks/BM_readChunk.cpp | 11 ++++--- benchmarks/BM_readChunkFlac.cpp | 11 ++++--- benchmarks/BM_resample.cpp | 10 +++--- benchmarks/BM_wavfile.cpp | 56 ++++++++++++++++++++------------- benchmarks/CMakeLists.txt | 30 ++++++++++++------ 6 files changed, 108 insertions(+), 65 deletions(-) diff --git a/benchmarks/BM_flacfile.cpp b/benchmarks/BM_flacfile.cpp index 4fedae8c3..bd599ee77 100644 --- a/benchmarks/BM_flacfile.cpp +++ b/benchmarks/BM_flacfile.cpp @@ -9,13 +9,16 @@ #include #define DR_FLAC_IMPLEMENTATION #include "dr_flac.h" -#include "ghc/filesystem.hpp" +#include "ghc/fs_std.hpp" #include "absl/memory/memory.h" #include #ifndef NDEBUG #include #endif -// #include "libnyquist/Decoders.h" +#if 0 +#include "libnyquist/Decoders.h" +#endif +#include // readlink class FileFixture : public benchmark::Fixture { public: @@ -23,9 +26,9 @@ class FileFixture : public benchmark::Fixture { filePath1 = getPath() / "sample1.flac"; filePath2 = getPath() / "sample2.flac"; filePath3 = getPath() / "sample3.flac"; - if ( !ghc::filesystem::exists(filePath1) - || !ghc::filesystem::exists(filePath2) - || !ghc::filesystem::exists(filePath3) ) { + if ( !fs::exists(filePath1) + || !fs::exists(filePath2) + || !fs::exists(filePath3) ) { #ifndef NDEBUG std::cerr << "Can't find path" << '\n'; #endif @@ -36,7 +39,7 @@ class FileFixture : public benchmark::Fixture { void TearDown(const ::benchmark::State& /* state */) { } - ghc::filesystem::path getPath() + fs::path getPath() { #ifdef __linux__ char buf[PATH_MAX + 1]; @@ -45,18 +48,18 @@ class FileFixture : public benchmark::Fixture { std::string str { buf }; return str.substr(0, str.rfind('/')); #elif _WIN32 - return ghc::filesystem::current_path(); + return fs::current_path(); #endif } std::unique_ptr> buffer; - ghc::filesystem::path filePath1; - ghc::filesystem::path filePath2; - ghc::filesystem::path filePath3; + fs::path filePath1; + fs::path filePath2; + fs::path filePath3; }; - +#if defined(SFIZZ_USE_SNDFILE) BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) { for (auto _ : state) { @@ -65,6 +68,7 @@ BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) { sndfile.readf(buffer->data(), sndfile.frames()); } } +#endif BENCHMARK_DEFINE_F(FileFixture, DrFlac)(benchmark::State& state) { for (auto _ : state) @@ -75,17 +79,26 @@ BENCHMARK_DEFINE_F(FileFixture, DrFlac)(benchmark::State& state) { } } -// BENCHMARK_DEFINE_F(FileFixture, LibNyquist)(benchmark::State& state) { -// for (auto _ : state) -// { -// nqr::AudioData data; -// nqr::NyquistIO loader; -// loader.Load(&data, filePath3.string()); -// benchmark::DoNotOptimize(data); -// } -// } +#if 0 +BENCHMARK_DEFINE_F(FileFixture, LibNyquist)(benchmark::State& state) { + for (auto _ : state) + { + nqr::AudioData data; + nqr::NyquistIO loader; + loader.Load(&data, filePath3.string()); + benchmark::DoNotOptimize(data); + } +} +#endif +#if defined(SFIZZ_USE_SNDFILE) BENCHMARK_REGISTER_F(FileFixture, SndFile); +#endif + BENCHMARK_REGISTER_F(FileFixture, DrFlac); -// BENCHMARK_REGISTER_F(FileFixture, LibNyquist); + +#if 0 +BENCHMARK_REGISTER_F(FileFixture, LibNyquist); +#endif + BENCHMARK_MAIN(); diff --git a/benchmarks/BM_readChunk.cpp b/benchmarks/BM_readChunk.cpp index 01b93aaa3..9e533cba5 100644 --- a/benchmarks/BM_readChunk.cpp +++ b/benchmarks/BM_readChunk.cpp @@ -8,7 +8,7 @@ #include "Buffer.h" #include #include -#include "ghc/filesystem.hpp" +#include "ghc/fs_std.hpp" #define DR_WAV_IMPLEMENTATION #include "dr_wav.h" #include "AudioBuffer.h" @@ -16,12 +16,13 @@ #ifndef NDEBUG #include #endif +#include // readlink class FileFixture : public benchmark::Fixture { public: void SetUp(const ::benchmark::State& /* state */) { rootPath = getPath() / "sample1.wav"; - if (!ghc::filesystem::exists(rootPath)) { + if (!fs::exists(rootPath)) { #ifndef NDEBUG std::cerr << "Can't find path" << '\n'; #endif @@ -36,7 +37,7 @@ class FileFixture : public benchmark::Fixture { void TearDown(const ::benchmark::State& /* state */) { } - ghc::filesystem::path getPath() + fs::path getPath() { #ifdef __linux__ char buf[PATH_MAX + 1]; @@ -45,13 +46,13 @@ class FileFixture : public benchmark::Fixture { std::string str { buf }; return str.substr(0, str.rfind('/')); #elif _WIN32 - return ghc::filesystem::current_path(); + return fs::current_path(); #endif } std::unique_ptr> output; SndfileHandle sndfile; - ghc::filesystem::path rootPath; + fs::path rootPath; size_t numFrames; }; diff --git a/benchmarks/BM_readChunkFlac.cpp b/benchmarks/BM_readChunkFlac.cpp index df77f6372..26bf9f458 100644 --- a/benchmarks/BM_readChunkFlac.cpp +++ b/benchmarks/BM_readChunkFlac.cpp @@ -8,7 +8,7 @@ #include "Buffer.h" #include #include -#include "ghc/filesystem.hpp" +#include "ghc/fs_std.hpp" #define DR_FLAC_IMPLEMENTATION #include "dr_flac.h" #include "AudioBuffer.h" @@ -16,12 +16,13 @@ #ifndef NDEBUG #include #endif +#include // readlink class FileFixture : public benchmark::Fixture { public: void SetUp(const ::benchmark::State& /* state */) { rootPath = getPath() / "sample1.flac"; - if (!ghc::filesystem::exists(rootPath)) { + if (!fs::exists(rootPath)) { #ifndef NDEBUG std::cerr << "Can't find path" << '\n'; #endif @@ -36,7 +37,7 @@ class FileFixture : public benchmark::Fixture { void TearDown(const ::benchmark::State& /* state */) { } - ghc::filesystem::path getPath() + fs::path getPath() { #ifdef __linux__ char buf[PATH_MAX + 1]; @@ -45,13 +46,13 @@ class FileFixture : public benchmark::Fixture { std::string str { buf }; return str.substr(0, str.rfind('/')); #elif _WIN32 - return ghc::filesystem::current_path(); + return fs::current_path(); #endif } std::unique_ptr> output; SndfileHandle sndfile; - ghc::filesystem::path rootPath; + fs::path rootPath; size_t numFrames; }; diff --git a/benchmarks/BM_resample.cpp b/benchmarks/BM_resample.cpp index ffd7f9023..dd122165d 100644 --- a/benchmarks/BM_resample.cpp +++ b/benchmarks/BM_resample.cpp @@ -11,8 +11,10 @@ #include "absl/memory/memory.h" #include #include -#include "ghc/filesystem.hpp" +#include "ghc/fs_std.hpp" #include "hiir/Upsampler2xFpu.h" +#include // readlink + constexpr std::array coeffsStage2x { 0.036681502163648017, 0.13654762463195771, @@ -192,7 +194,7 @@ class SndFile : public benchmark::Fixture { { const auto rootPath = getPath() / "sample1.wav"; - if (!ghc::filesystem::exists(rootPath)) { + if (!fs::exists(rootPath)) { #ifndef NDEBUG std::cerr << "Can't find path" << '\n'; #endif @@ -210,7 +212,7 @@ class SndFile : public benchmark::Fixture { { } - ghc::filesystem::path getPath() + fs::path getPath() { #ifdef __linux__ char buf[PATH_MAX + 1]; @@ -219,7 +221,7 @@ class SndFile : public benchmark::Fixture { std::string str { buf }; return str.substr(0, str.rfind('/')); #elif _WIN32 - return ghc::filesystem::current_path(); + return fs::current_path(); #endif } diff --git a/benchmarks/BM_wavfile.cpp b/benchmarks/BM_wavfile.cpp index a4533195a..919e87f0b 100644 --- a/benchmarks/BM_wavfile.cpp +++ b/benchmarks/BM_wavfile.cpp @@ -3,17 +3,23 @@ // 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 "Buffer.h" #include +#if defined(SFIZZ_USE_SNDFILE) #include +#endif #define DR_WAV_IMPLEMENTATION #include "dr_wav.h" -#include "ghc/filesystem.hpp" +#include "ghc/fs_std.hpp" #include "absl/memory/memory.h" +#if 0 +#include "libnyquist/Decoders.h" +#endif #ifndef NDEBUG #include #endif -// #include "libnyquist/Decoders.h" +#include // readlink class FileFixture : public benchmark::Fixture { public: @@ -21,9 +27,9 @@ class FileFixture : public benchmark::Fixture { filePath1 = getPath() / "sample1.wav"; filePath2 = getPath() / "sample2.wav"; filePath3 = getPath() / "sample3.wav"; - if ( !ghc::filesystem::exists(filePath1) - || !ghc::filesystem::exists(filePath2) - || !ghc::filesystem::exists(filePath3)) { + if ( !fs::exists(filePath1) + || !fs::exists(filePath2) + || !fs::exists(filePath3)) { #ifndef NDEBUG std::cerr << "Can't find path" << '\n'; #endif @@ -34,7 +40,7 @@ class FileFixture : public benchmark::Fixture { void TearDown(const ::benchmark::State& /* state */) { } - ghc::filesystem::path getPath() + fs::path getPath() { #ifdef __linux__ char buf[PATH_MAX + 1]; @@ -43,18 +49,18 @@ class FileFixture : public benchmark::Fixture { std::string str { buf }; return str.substr(0, str.rfind('/')); #elif _WIN32 - return ghc::filesystem::current_path(); + return fs::current_path(); #endif } std::unique_ptr> buffer; - ghc::filesystem::path filePath1; - ghc::filesystem::path filePath2; - ghc::filesystem::path filePath3; + fs::path filePath1; + fs::path filePath2; + fs::path filePath3; }; - +#if defined(SFIZZ_USE_SNDFILE) BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) { for (auto _ : state) { @@ -63,6 +69,7 @@ BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) { sndfile.readf(buffer->data(), sndfile.frames()); } } +#endif BENCHMARK_DEFINE_F(FileFixture, DrWav)(benchmark::State& state) { for (auto _ : state) @@ -79,17 +86,24 @@ BENCHMARK_DEFINE_F(FileFixture, DrWav)(benchmark::State& state) { } } -// BENCHMARK_DEFINE_F(FileFixture, LibNyquist)(benchmark::State& state) { -// for (auto _ : state) -// { -// nqr::AudioData data; -// nqr::NyquistIO loader; -// loader.Load(&data, filePath3.string()); -// benchmark::DoNotOptimize(data); -// } -// } +#if 0 +BENCHMARK_DEFINE_F(FileFixture, LibNyquist)(benchmark::State& state) { + for (auto _ : state) + { + nqr::AudioData data; + nqr::NyquistIO loader; + loader.Load(&data, filePath3.string()); + benchmark::DoNotOptimize(data); + } +} +#endif +#if defined(SFIZZ_USE_SNDFILE) BENCHMARK_REGISTER_F(FileFixture, SndFile); +#endif BENCHMARK_REGISTER_F(FileFixture, DrWav); -// BENCHMARK_REGISTER_F(FileFixture, LibNyquist); + +#if 0 +BENCHMARK_REGISTER_F(FileFixture, LibNyquist); +#endif BENCHMARK_MAIN(); diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index 68145e2dc..49c9c0cc4 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -18,7 +18,10 @@ sfizz_add_benchmark(bm_mathfuns BM_mathfuns.cpp) sfizz_add_benchmark(bm_gain BM_gain.cpp) sfizz_add_benchmark(bm_divide BM_divide.cpp) sfizz_add_benchmark(bm_ramp BM_ramp.cpp) + +if(0) #FIXME sfizz_add_benchmark(bm_ADSR BM_ADSR.cpp) +endif() sfizz_add_benchmark(bm_add BM_add.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_allWithin BM_allWithin.cpp) +if(0) #FIXME sfizz_add_benchmark(bm_logger BM_logger.cpp) +endif() + sfizz_add_benchmark(bm_smoothers BM_smoothers.cpp) sfizz_add_benchmark(bm_powerFollower BM_powerFollower.cpp) -if(TARGET sfizz::samplerate) -sfizz_add_benchmark(bm_resample BM_resample.cpp ${BENCHMARK_SIMD_SOURCES}) -target_link_libraries(bm_resample PRIVATE sfizz::samplerate sfizz::sndfile sfizz::hiir) +if(SFIZZ_USE_SNDFILE) + if(TARGET sfizz::samplerate) + 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() 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) target_link_libraries(bm_flacfile PRIVATE sfizz::sndfile) -sfizz_add_benchmark(bm_audioReaders BM_audioReaders.cpp ../src/sfizz/AudioReader.cpp) -target_link_libraries(bm_audioReaders PRIVATE st_audiofile sfizz::sndfile) +if(SFIZZ_USE_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) -target_link_libraries(bm_readChunk PRIVATE sfizz::sndfile) -sfizz_add_benchmark(bm_readChunkFlac BM_readChunkFlac.cpp) -target_link_libraries(bm_readChunkFlac PRIVATE sfizz::sndfile) +if(SFIZZ_USE_SNDFILE) + sfizz_add_benchmark(bm_readChunk BM_readChunk.cpp) + target_link_libraries(bm_readChunk 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)