Skip to content

Commit 56b0f4d

Browse files
committed
Temporary fixes for benchmarks, see sfztools#1148
1 parent 9a3e371 commit 56b0f4d

6 files changed

+108
-65
lines changed

benchmarks/BM_flacfile.cpp

+34-21
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,26 @@
99
#include <sndfile.hh>
1010
#define DR_FLAC_IMPLEMENTATION
1111
#include "dr_flac.h"
12-
#include "ghc/filesystem.hpp"
12+
#include "ghc/fs_std.hpp"
1313
#include "absl/memory/memory.h"
1414
#include <memory>
1515
#ifndef NDEBUG
1616
#include <iostream>
1717
#endif
18-
// #include "libnyquist/Decoders.h"
18+
#if 0
19+
#include "libnyquist/Decoders.h"
20+
#endif
21+
#include <unistd.h> // readlink
1922

2023
class FileFixture : public benchmark::Fixture {
2124
public:
2225
void SetUp(const ::benchmark::State& /* state */) {
2326
filePath1 = getPath() / "sample1.flac";
2427
filePath2 = getPath() / "sample2.flac";
2528
filePath3 = getPath() / "sample3.flac";
26-
if ( !ghc::filesystem::exists(filePath1)
27-
|| !ghc::filesystem::exists(filePath2)
28-
|| !ghc::filesystem::exists(filePath3) ) {
29+
if ( !fs::exists(filePath1)
30+
|| !fs::exists(filePath2)
31+
|| !fs::exists(filePath3) ) {
2932
#ifndef NDEBUG
3033
std::cerr << "Can't find path" << '\n';
3134
#endif
@@ -36,7 +39,7 @@ class FileFixture : public benchmark::Fixture {
3639
void TearDown(const ::benchmark::State& /* state */) {
3740
}
3841

39-
ghc::filesystem::path getPath()
42+
fs::path getPath()
4043
{
4144
#ifdef __linux__
4245
char buf[PATH_MAX + 1];
@@ -45,18 +48,18 @@ class FileFixture : public benchmark::Fixture {
4548
std::string str { buf };
4649
return str.substr(0, str.rfind('/'));
4750
#elif _WIN32
48-
return ghc::filesystem::current_path();
51+
return fs::current_path();
4952
#endif
5053
}
5154

5255
std::unique_ptr<sfz::Buffer<float>> buffer;
5356

54-
ghc::filesystem::path filePath1;
55-
ghc::filesystem::path filePath2;
56-
ghc::filesystem::path filePath3;
57+
fs::path filePath1;
58+
fs::path filePath2;
59+
fs::path filePath3;
5760
};
5861

59-
62+
#if defined(SFIZZ_USE_SNDFILE)
6063
BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) {
6164
for (auto _ : state)
6265
{
@@ -65,6 +68,7 @@ BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) {
6568
sndfile.readf(buffer->data(), sndfile.frames());
6669
}
6770
}
71+
#endif
6872

6973
BENCHMARK_DEFINE_F(FileFixture, DrFlac)(benchmark::State& state) {
7074
for (auto _ : state)
@@ -75,17 +79,26 @@ BENCHMARK_DEFINE_F(FileFixture, DrFlac)(benchmark::State& state) {
7579
}
7680
}
7781

78-
// BENCHMARK_DEFINE_F(FileFixture, LibNyquist)(benchmark::State& state) {
79-
// for (auto _ : state)
80-
// {
81-
// nqr::AudioData data;
82-
// nqr::NyquistIO loader;
83-
// loader.Load(&data, filePath3.string());
84-
// benchmark::DoNotOptimize(data);
85-
// }
86-
// }
82+
#if 0
83+
BENCHMARK_DEFINE_F(FileFixture, LibNyquist)(benchmark::State& state) {
84+
for (auto _ : state)
85+
{
86+
nqr::AudioData data;
87+
nqr::NyquistIO loader;
88+
loader.Load(&data, filePath3.string());
89+
benchmark::DoNotOptimize(data);
90+
}
91+
}
92+
#endif
8793

94+
#if defined(SFIZZ_USE_SNDFILE)
8895
BENCHMARK_REGISTER_F(FileFixture, SndFile);
96+
#endif
97+
8998
BENCHMARK_REGISTER_F(FileFixture, DrFlac);
90-
// BENCHMARK_REGISTER_F(FileFixture, LibNyquist);
99+
100+
#if 0
101+
BENCHMARK_REGISTER_F(FileFixture, LibNyquist);
102+
#endif
103+
91104
BENCHMARK_MAIN();

benchmarks/BM_readChunk.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@
88
#include "Buffer.h"
99
#include <benchmark/benchmark.h>
1010
#include <sndfile.hh>
11-
#include "ghc/filesystem.hpp"
11+
#include "ghc/fs_std.hpp"
1212
#define DR_WAV_IMPLEMENTATION
1313
#include "dr_wav.h"
1414
#include "AudioBuffer.h"
1515
#include "absl/memory/memory.h"
1616
#ifndef NDEBUG
1717
#include <iostream>
1818
#endif
19+
#include <unistd.h> // readlink
1920

2021
class FileFixture : public benchmark::Fixture {
2122
public:
2223
void SetUp(const ::benchmark::State& /* state */) {
2324
rootPath = getPath() / "sample1.wav";
24-
if (!ghc::filesystem::exists(rootPath)) {
25+
if (!fs::exists(rootPath)) {
2526
#ifndef NDEBUG
2627
std::cerr << "Can't find path" << '\n';
2728
#endif
@@ -36,7 +37,7 @@ class FileFixture : public benchmark::Fixture {
3637
void TearDown(const ::benchmark::State& /* state */) {
3738
}
3839

39-
ghc::filesystem::path getPath()
40+
fs::path getPath()
4041
{
4142
#ifdef __linux__
4243
char buf[PATH_MAX + 1];
@@ -45,13 +46,13 @@ class FileFixture : public benchmark::Fixture {
4546
std::string str { buf };
4647
return str.substr(0, str.rfind('/'));
4748
#elif _WIN32
48-
return ghc::filesystem::current_path();
49+
return fs::current_path();
4950
#endif
5051
}
5152

5253
std::unique_ptr<sfz::AudioBuffer<float>> output;
5354
SndfileHandle sndfile;
54-
ghc::filesystem::path rootPath;
55+
fs::path rootPath;
5556
size_t numFrames;
5657
};
5758

benchmarks/BM_readChunkFlac.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@
88
#include "Buffer.h"
99
#include <benchmark/benchmark.h>
1010
#include <sndfile.hh>
11-
#include "ghc/filesystem.hpp"
11+
#include "ghc/fs_std.hpp"
1212
#define DR_FLAC_IMPLEMENTATION
1313
#include "dr_flac.h"
1414
#include "AudioBuffer.h"
1515
#include "absl/memory/memory.h"
1616
#ifndef NDEBUG
1717
#include <iostream>
1818
#endif
19+
#include <unistd.h> // readlink
1920

2021
class FileFixture : public benchmark::Fixture {
2122
public:
2223
void SetUp(const ::benchmark::State& /* state */) {
2324
rootPath = getPath() / "sample1.flac";
24-
if (!ghc::filesystem::exists(rootPath)) {
25+
if (!fs::exists(rootPath)) {
2526
#ifndef NDEBUG
2627
std::cerr << "Can't find path" << '\n';
2728
#endif
@@ -36,7 +37,7 @@ class FileFixture : public benchmark::Fixture {
3637
void TearDown(const ::benchmark::State& /* state */) {
3738
}
3839

39-
ghc::filesystem::path getPath()
40+
fs::path getPath()
4041
{
4142
#ifdef __linux__
4243
char buf[PATH_MAX + 1];
@@ -45,13 +46,13 @@ class FileFixture : public benchmark::Fixture {
4546
std::string str { buf };
4647
return str.substr(0, str.rfind('/'));
4748
#elif _WIN32
48-
return ghc::filesystem::current_path();
49+
return fs::current_path();
4950
#endif
5051
}
5152

5253
std::unique_ptr<sfz::AudioBuffer<float>> output;
5354
SndfileHandle sndfile;
54-
ghc::filesystem::path rootPath;
55+
fs::path rootPath;
5556
size_t numFrames;
5657
};
5758

benchmarks/BM_resample.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
#include "absl/memory/memory.h"
1212
#include <samplerate.h>
1313
#include <sndfile.hh>
14-
#include "ghc/filesystem.hpp"
14+
#include "ghc/fs_std.hpp"
1515
#include "hiir/Upsampler2xFpu.h"
16+
#include <unistd.h> // readlink
17+
1618
constexpr std::array<double, 12> coeffsStage2x {
1719
0.036681502163648017,
1820
0.13654762463195771,
@@ -192,7 +194,7 @@ class SndFile : public benchmark::Fixture {
192194
{
193195

194196
const auto rootPath = getPath() / "sample1.wav";
195-
if (!ghc::filesystem::exists(rootPath)) {
197+
if (!fs::exists(rootPath)) {
196198
#ifndef NDEBUG
197199
std::cerr << "Can't find path" << '\n';
198200
#endif
@@ -210,7 +212,7 @@ class SndFile : public benchmark::Fixture {
210212
{
211213
}
212214

213-
ghc::filesystem::path getPath()
215+
fs::path getPath()
214216
{
215217
#ifdef __linux__
216218
char buf[PATH_MAX + 1];
@@ -219,7 +221,7 @@ class SndFile : public benchmark::Fixture {
219221
std::string str { buf };
220222
return str.substr(0, str.rfind('/'));
221223
#elif _WIN32
222-
return ghc::filesystem::current_path();
224+
return fs::current_path();
223225
#endif
224226
}
225227

benchmarks/BM_wavfile.cpp

+35-21
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,33 @@
33
// This code is part of the sfizz library and is licensed under a BSD 2-clause
44
// license. You should have receive a LICENSE.md file along with the code.
55
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
6+
67
#include "Buffer.h"
78
#include <benchmark/benchmark.h>
9+
#if defined(SFIZZ_USE_SNDFILE)
810
#include <sndfile.hh>
11+
#endif
912
#define DR_WAV_IMPLEMENTATION
1013
#include "dr_wav.h"
11-
#include "ghc/filesystem.hpp"
14+
#include "ghc/fs_std.hpp"
1215
#include "absl/memory/memory.h"
16+
#if 0
17+
#include "libnyquist/Decoders.h"
18+
#endif
1319
#ifndef NDEBUG
1420
#include <iostream>
1521
#endif
16-
// #include "libnyquist/Decoders.h"
22+
#include <unistd.h> // readlink
1723

1824
class FileFixture : public benchmark::Fixture {
1925
public:
2026
void SetUp(const ::benchmark::State& /* state */) {
2127
filePath1 = getPath() / "sample1.wav";
2228
filePath2 = getPath() / "sample2.wav";
2329
filePath3 = getPath() / "sample3.wav";
24-
if ( !ghc::filesystem::exists(filePath1)
25-
|| !ghc::filesystem::exists(filePath2)
26-
|| !ghc::filesystem::exists(filePath3)) {
30+
if ( !fs::exists(filePath1)
31+
|| !fs::exists(filePath2)
32+
|| !fs::exists(filePath3)) {
2733
#ifndef NDEBUG
2834
std::cerr << "Can't find path" << '\n';
2935
#endif
@@ -34,7 +40,7 @@ class FileFixture : public benchmark::Fixture {
3440
void TearDown(const ::benchmark::State& /* state */) {
3541
}
3642

37-
ghc::filesystem::path getPath()
43+
fs::path getPath()
3844
{
3945
#ifdef __linux__
4046
char buf[PATH_MAX + 1];
@@ -43,18 +49,18 @@ class FileFixture : public benchmark::Fixture {
4349
std::string str { buf };
4450
return str.substr(0, str.rfind('/'));
4551
#elif _WIN32
46-
return ghc::filesystem::current_path();
52+
return fs::current_path();
4753
#endif
4854
}
4955

5056
std::unique_ptr<sfz::Buffer<float>> buffer;
5157

52-
ghc::filesystem::path filePath1;
53-
ghc::filesystem::path filePath2;
54-
ghc::filesystem::path filePath3;
58+
fs::path filePath1;
59+
fs::path filePath2;
60+
fs::path filePath3;
5561
};
5662

57-
63+
#if defined(SFIZZ_USE_SNDFILE)
5864
BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) {
5965
for (auto _ : state)
6066
{
@@ -63,6 +69,7 @@ BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) {
6369
sndfile.readf(buffer->data(), sndfile.frames());
6470
}
6571
}
72+
#endif
6673

6774
BENCHMARK_DEFINE_F(FileFixture, DrWav)(benchmark::State& state) {
6875
for (auto _ : state)
@@ -79,17 +86,24 @@ BENCHMARK_DEFINE_F(FileFixture, DrWav)(benchmark::State& state) {
7986
}
8087
}
8188

82-
// BENCHMARK_DEFINE_F(FileFixture, LibNyquist)(benchmark::State& state) {
83-
// for (auto _ : state)
84-
// {
85-
// nqr::AudioData data;
86-
// nqr::NyquistIO loader;
87-
// loader.Load(&data, filePath3.string());
88-
// benchmark::DoNotOptimize(data);
89-
// }
90-
// }
89+
#if 0
90+
BENCHMARK_DEFINE_F(FileFixture, LibNyquist)(benchmark::State& state) {
91+
for (auto _ : state)
92+
{
93+
nqr::AudioData data;
94+
nqr::NyquistIO loader;
95+
loader.Load(&data, filePath3.string());
96+
benchmark::DoNotOptimize(data);
97+
}
98+
}
99+
#endif
91100

101+
#if defined(SFIZZ_USE_SNDFILE)
92102
BENCHMARK_REGISTER_F(FileFixture, SndFile);
103+
#endif
93104
BENCHMARK_REGISTER_F(FileFixture, DrWav);
94-
// BENCHMARK_REGISTER_F(FileFixture, LibNyquist);
105+
106+
#if 0
107+
BENCHMARK_REGISTER_F(FileFixture, LibNyquist);
108+
#endif
95109
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)