3
3
// This code is part of the sfizz library and is licensed under a BSD 2-clause
4
4
// license. You should have receive a LICENSE.md file along with the code.
5
5
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
6
+
6
7
#include " Buffer.h"
7
8
#include < benchmark/benchmark.h>
9
+ #if defined(SFIZZ_USE_SNDFILE)
8
10
#include < sndfile.hh>
11
+ #endif
9
12
#define DR_WAV_IMPLEMENTATION
10
13
#include " dr_wav.h"
11
- #include " ghc/filesystem .hpp"
14
+ #include " ghc/fs_std .hpp"
12
15
#include " absl/memory/memory.h"
16
+ #if 0
17
+ #include "libnyquist/Decoders.h"
18
+ #endif
13
19
#ifndef NDEBUG
14
20
#include < iostream>
15
21
#endif
16
- // #include "libnyquist/Decoders.h"
22
+ #include < unistd.h > // readlink
17
23
18
24
class FileFixture : public benchmark ::Fixture {
19
25
public:
20
26
void SetUp (const ::benchmark::State& /* state */ ) {
21
27
filePath1 = getPath () / " sample1.wav" ;
22
28
filePath2 = getPath () / " sample2.wav" ;
23
29
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)) {
27
33
#ifndef NDEBUG
28
34
std::cerr << " Can't find path" << ' \n ' ;
29
35
#endif
@@ -34,7 +40,7 @@ class FileFixture : public benchmark::Fixture {
34
40
void TearDown (const ::benchmark::State& /* state */ ) {
35
41
}
36
42
37
- ghc::filesystem ::path getPath ()
43
+ fs ::path getPath ()
38
44
{
39
45
#ifdef __linux__
40
46
char buf[PATH_MAX + 1 ];
@@ -43,18 +49,18 @@ class FileFixture : public benchmark::Fixture {
43
49
std::string str { buf };
44
50
return str.substr (0 , str.rfind (' /' ));
45
51
#elif _WIN32
46
- return ghc::filesystem ::current_path ();
52
+ return fs ::current_path ();
47
53
#endif
48
54
}
49
55
50
56
std::unique_ptr<sfz::Buffer<float >> buffer;
51
57
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;
55
61
};
56
62
57
-
63
+ # if defined(SFIZZ_USE_SNDFILE)
58
64
BENCHMARK_DEFINE_F (FileFixture, SndFile)(benchmark::State& state) {
59
65
for (auto _ : state)
60
66
{
@@ -63,6 +69,7 @@ BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) {
63
69
sndfile.readf (buffer->data (), sndfile.frames ());
64
70
}
65
71
}
72
+ #endif
66
73
67
74
BENCHMARK_DEFINE_F (FileFixture, DrWav)(benchmark::State& state) {
68
75
for (auto _ : state)
@@ -79,17 +86,24 @@ BENCHMARK_DEFINE_F(FileFixture, DrWav)(benchmark::State& state) {
79
86
}
80
87
}
81
88
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
91
100
101
+ #if defined(SFIZZ_USE_SNDFILE)
92
102
BENCHMARK_REGISTER_F (FileFixture, SndFile);
103
+ #endif
93
104
BENCHMARK_REGISTER_F (FileFixture, DrWav);
94
- // BENCHMARK_REGISTER_F(FileFixture, LibNyquist);
105
+
106
+ #if 0
107
+ BENCHMARK_REGISTER_F(FileFixture, LibNyquist);
108
+ #endif
95
109
BENCHMARK_MAIN ();
0 commit comments