Skip to content

Commit

Permalink
Temporary fixes for benchmarks, see sfztools#1148
Browse files Browse the repository at this point in the history
  • Loading branch information
redtide committed May 21, 2023
1 parent 9a3e371 commit 56b0f4d
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 65 deletions.
55 changes: 34 additions & 21 deletions benchmarks/BM_flacfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,26 @@
#include <sndfile.hh>
#define DR_FLAC_IMPLEMENTATION
#include "dr_flac.h"
#include "ghc/filesystem.hpp"
#include "ghc/fs_std.hpp"
#include "absl/memory/memory.h"
#include <memory>
#ifndef NDEBUG
#include <iostream>
#endif
// #include "libnyquist/Decoders.h"
#if 0
#include "libnyquist/Decoders.h"
#endif
#include <unistd.h> // readlink

class FileFixture : public benchmark::Fixture {
public:
void SetUp(const ::benchmark::State& /* state */) {
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
Expand All @@ -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];
Expand All @@ -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<sfz::Buffer<float>> 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)
{
Expand All @@ -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)
Expand All @@ -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();
11 changes: 6 additions & 5 deletions benchmarks/BM_readChunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@
#include "Buffer.h"
#include <benchmark/benchmark.h>
#include <sndfile.hh>
#include "ghc/filesystem.hpp"
#include "ghc/fs_std.hpp"
#define DR_WAV_IMPLEMENTATION
#include "dr_wav.h"
#include "AudioBuffer.h"
#include "absl/memory/memory.h"
#ifndef NDEBUG
#include <iostream>
#endif
#include <unistd.h> // 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
Expand All @@ -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];
Expand All @@ -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<sfz::AudioBuffer<float>> output;
SndfileHandle sndfile;
ghc::filesystem::path rootPath;
fs::path rootPath;
size_t numFrames;
};

Expand Down
11 changes: 6 additions & 5 deletions benchmarks/BM_readChunkFlac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@
#include "Buffer.h"
#include <benchmark/benchmark.h>
#include <sndfile.hh>
#include "ghc/filesystem.hpp"
#include "ghc/fs_std.hpp"
#define DR_FLAC_IMPLEMENTATION
#include "dr_flac.h"
#include "AudioBuffer.h"
#include "absl/memory/memory.h"
#ifndef NDEBUG
#include <iostream>
#endif
#include <unistd.h> // 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
Expand All @@ -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];
Expand All @@ -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<sfz::AudioBuffer<float>> output;
SndfileHandle sndfile;
ghc::filesystem::path rootPath;
fs::path rootPath;
size_t numFrames;
};

Expand Down
10 changes: 6 additions & 4 deletions benchmarks/BM_resample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#include "absl/memory/memory.h"
#include <samplerate.h>
#include <sndfile.hh>
#include "ghc/filesystem.hpp"
#include "ghc/fs_std.hpp"
#include "hiir/Upsampler2xFpu.h"
#include <unistd.h> // readlink

constexpr std::array<double, 12> coeffsStage2x {
0.036681502163648017,
0.13654762463195771,
Expand Down Expand Up @@ -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
Expand All @@ -210,7 +212,7 @@ class SndFile : public benchmark::Fixture {
{
}

ghc::filesystem::path getPath()
fs::path getPath()
{
#ifdef __linux__
char buf[PATH_MAX + 1];
Expand All @@ -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
}

Expand Down
56 changes: 35 additions & 21 deletions benchmarks/BM_wavfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,33 @@
// 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 <benchmark/benchmark.h>
#if defined(SFIZZ_USE_SNDFILE)
#include <sndfile.hh>
#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 <iostream>
#endif
// #include "libnyquist/Decoders.h"
#include <unistd.h> // readlink

class FileFixture : public benchmark::Fixture {
public:
void SetUp(const ::benchmark::State& /* state */) {
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
Expand All @@ -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];
Expand All @@ -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<sfz::Buffer<float>> 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)
{
Expand All @@ -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)
Expand All @@ -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();
Loading

0 comments on commit 56b0f4d

Please sign in to comment.