Added libnyquist to the file benchmark

This commit is contained in:
Paul Ferrand 2020-01-05 10:51:06 +01:00
parent 0e76a67368
commit bd2762c9f7
5 changed files with 62 additions and 16 deletions

View file

@ -30,13 +30,17 @@
#ifndef NDEBUG
#include <iostream>
#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<sfz::Buffer<float>> 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<sfz::Buffer<float>>(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<sfz::Buffer<float>>(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();

View file

@ -30,13 +30,17 @@
#ifndef NDEBUG
#include <iostream>
#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<sfz::Buffer<float>> 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<sfz::Buffer<float>>(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();

View file

@ -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)

BIN
benchmarks/sample3.flac Executable file

Binary file not shown.

BIN
benchmarks/sample3.wav Executable file

Binary file not shown.