diff --git a/benchmarks/BM_flacfile.cpp b/benchmarks/BM_flacfile.cpp index 6f5ec187..0352fced 100644 --- a/benchmarks/BM_flacfile.cpp +++ b/benchmarks/BM_flacfile.cpp @@ -30,13 +30,17 @@ #ifndef NDEBUG #include #endif +#include "libnyquist/Decoders.h" class FileFixture : public benchmark::Fixture { public: void SetUp(const ::benchmark::State& state) { - rootPath1 = getPath() / "sample1.flac"; - rootPath2 = getPath() / "sample2.flac"; - if (!ghc::filesystem::exists(rootPath1) || !ghc::filesystem::exists(rootPath2)) { + 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) ) { #ifndef NDEBUG std::cerr << "Can't find path" << '\n'; #endif @@ -62,15 +66,16 @@ public: std::unique_ptr> buffer; - ghc::filesystem::path rootPath1; - ghc::filesystem::path rootPath2; + ghc::filesystem::path filePath1; + ghc::filesystem::path filePath2; + ghc::filesystem::path filePath3; }; BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) { for (auto _ : state) { - SndfileHandle sndfile(rootPath1.c_str()); + SndfileHandle sndfile(filePath1.c_str()); buffer = std::make_unique>(sndfile.channels() * sndfile.frames()); sndfile.readf(buffer->data(), sndfile.frames()); } @@ -79,12 +84,23 @@ BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) { BENCHMARK_DEFINE_F(FileFixture, DrFlac)(benchmark::State& state) { for (auto _ : state) { - auto* flac = drflac_open_file(rootPath2.c_str(), nullptr); + auto* flac = drflac_open_file(filePath2.c_str(), nullptr); buffer = std::make_unique>(flac->channels * flac->totalPCMFrameCount); drflac_read_pcm_frames_f32(flac, flac->totalPCMFrameCount, buffer->data()); } } +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); + } +} + BENCHMARK_REGISTER_F(FileFixture, SndFile); BENCHMARK_REGISTER_F(FileFixture, DrFlac); +BENCHMARK_REGISTER_F(FileFixture, LibNyquist); BENCHMARK_MAIN(); diff --git a/benchmarks/BM_wavfile.cpp b/benchmarks/BM_wavfile.cpp index 0bf503bf..75d6d576 100644 --- a/benchmarks/BM_wavfile.cpp +++ b/benchmarks/BM_wavfile.cpp @@ -30,13 +30,17 @@ #ifndef NDEBUG #include #endif +#include "libnyquist/Decoders.h" class FileFixture : public benchmark::Fixture { public: void SetUp(const ::benchmark::State& state) { - rootPath1 = getPath() / "sample1.wav"; - rootPath2 = getPath() / "sample2.wav"; - if (!ghc::filesystem::exists(rootPath1) || !ghc::filesystem::exists(rootPath2)) { + 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)) { #ifndef NDEBUG std::cerr << "Can't find path" << '\n'; #endif @@ -62,15 +66,16 @@ public: std::unique_ptr> buffer; - ghc::filesystem::path rootPath1; - ghc::filesystem::path rootPath2; + ghc::filesystem::path filePath1; + ghc::filesystem::path filePath2; + ghc::filesystem::path filePath3; }; BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) { for (auto _ : state) { - SndfileHandle sndfile(rootPath1.c_str()); + SndfileHandle sndfile(filePath1.c_str()); buffer = std::make_unique>(sndfile.channels() * sndfile.frames()); sndfile.readf(buffer->data(), sndfile.frames()); } @@ -80,7 +85,7 @@ BENCHMARK_DEFINE_F(FileFixture, DrWav)(benchmark::State& state) { for (auto _ : state) { drwav wav; - if (!drwav_init_file(&wav, rootPath2.c_str(), nullptr)) { + if (!drwav_init_file(&wav, filePath2.c_str(), nullptr)) { #ifndef NDEBUG std::cerr << "Can't find path" << '\n'; #endif @@ -91,6 +96,17 @@ 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); + } +} + BENCHMARK_REGISTER_F(FileFixture, SndFile); BENCHMARK_REGISTER_F(FileFixture, DrWav); +BENCHMARK_REGISTER_F(FileFixture, LibNyquist); BENCHMARK_MAIN(); diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index 0f9a9824..038069a2 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -119,13 +119,25 @@ add_executable(bm_envelopes BM_envelopes.cpp ${BENCHMARK_SIMD_SOURCES}) target_link_libraries(bm_envelopes PRIVATE benchmark absl::span absl::algorithm) target_include_directories(bm_envelopes PRIVATE ../src/sfizz ../src/external) +include(FetchContent) +FetchContent_Declare( + libnyquist + GIT_REPOSITORY https://github.com/paulfd/libnyquist +) + +FetchContent_GetProperties(libnyquist) +if(NOT libnyquist_POPULATED) + FetchContent_Populate(libnyquist) + add_subdirectory(${libnyquist_SOURCE_DIR} ${libnyquist_BINARY_DIR} EXCLUDE_FROM_ALL) +endif() + add_executable(bm_wavfile BM_wavfile.cpp ${BENCHMARK_SIMD_SOURCES}) -target_link_libraries(bm_wavfile PRIVATE benchmark absl::span absl::algorithm) +target_link_libraries(bm_wavfile PRIVATE benchmark absl::span absl::algorithm libnyquist) sfizz_link_libsndfile(bm_wavfile) target_include_directories(bm_wavfile PRIVATE ../src/sfizz ../src/external) add_executable(bm_flacfile BM_flacfile.cpp ${BENCHMARK_SIMD_SOURCES}) -target_link_libraries(bm_flacfile PRIVATE benchmark absl::span absl::algorithm) +target_link_libraries(bm_flacfile PRIVATE benchmark absl::span absl::algorithm libnyquist) sfizz_link_libsndfile(bm_flacfile) target_include_directories(bm_flacfile PRIVATE ../src/sfizz ../src/external) @@ -172,5 +184,7 @@ add_dependencies(sfizz_benchmarks file(COPY "sample1.wav" DESTINATION ${CMAKE_BINARY_DIR}/benchmarks) file(COPY "sample2.wav" DESTINATION ${CMAKE_BINARY_DIR}/benchmarks) +file(COPY "sample3.wav" DESTINATION ${CMAKE_BINARY_DIR}/benchmarks) file(COPY "sample1.flac" DESTINATION ${CMAKE_BINARY_DIR}/benchmarks) file(COPY "sample2.flac" DESTINATION ${CMAKE_BINARY_DIR}/benchmarks) +file(COPY "sample3.flac" DESTINATION ${CMAKE_BINARY_DIR}/benchmarks) diff --git a/benchmarks/sample3.flac b/benchmarks/sample3.flac new file mode 100755 index 00000000..3b84350a Binary files /dev/null and b/benchmarks/sample3.flac differ diff --git a/benchmarks/sample3.wav b/benchmarks/sample3.wav new file mode 100755 index 00000000..2acb8351 Binary files /dev/null and b/benchmarks/sample3.wav differ