-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio_buffer_benchmark.cpp
More file actions
48 lines (37 loc) · 1.21 KB
/
audio_buffer_benchmark.cpp
File metadata and controls
48 lines (37 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: MIT
#include "audio_buffer.h"
#include <benchmark/benchmark.h>
#include <vector>
namespace {
void Write16Bit(benchmark::State &state) {
constexpr plac::AudioFormat format{16, 2, 96000};
constexpr std::size_t size{57000};
plac::AudioBuffer<AsBytes(format, size)> b;
std::vector<int> left;
std::vector<int> right;
left.resize(size);
right.resize(size);
for (auto _ : state) {
benchmark::DoNotOptimize(b.Write(format, left.data(), right.data(), size));
benchmark::ClobberMemory();
b.Drain(format, [](plac::AudioFormat, const u_char *, const size_t count) { return count; });
}
}
void Write24Bit(benchmark::State &state) {
constexpr plac::AudioFormat format{24, 2, 96000};
constexpr std::size_t size{57000};
plac::AudioBuffer<AsBytes(format, size)> b;
std::vector<int> left;
std::vector<int> right;
left.resize(size);
right.resize(size);
for (auto _ : state) {
benchmark::DoNotOptimize(b.Write(format, left.data(), right.data(), size));
benchmark::ClobberMemory();
b.Drain(format, [](plac::AudioFormat, const u_char *, const size_t count) { return count; });
}
}
BENCHMARK(Write16Bit);
BENCHMARK(Write24Bit);
} // namespace
BENCHMARK_MAIN();