Added a benchmark for wav libraries
This commit is contained in:
parent
92aaa2a17e
commit
c6d29e8ccd
4 changed files with 5460 additions and 0 deletions
96
benchmarks/BM_wavfile.cpp
Normal file
96
benchmarks/BM_wavfile.cpp
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
// Copyright (c) 2019, Paul Ferrand
|
||||
// All rights reserved.
|
||||
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <sndfile.hh>
|
||||
#define DR_WAV_IMPLEMENTATION
|
||||
#include "dr_wav.h"
|
||||
#include "ghc/filesystem.hpp"
|
||||
#include "Buffer.h"
|
||||
#include <memory>
|
||||
#ifndef NDEBUG
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
class FileFixture : public benchmark::Fixture {
|
||||
public:
|
||||
void SetUp(const ::benchmark::State& state) {
|
||||
rootPath1 = getPath() / "ride.wav";
|
||||
rootPath2 = getPath() / "ride2.wav";
|
||||
if (!ghc::filesystem::exists(rootPath1) || !ghc::filesystem::exists(rootPath2)) {
|
||||
#ifndef NDEBUG
|
||||
std::cerr << "Can't find path" << '\n';
|
||||
#endif
|
||||
std::terminate();
|
||||
}
|
||||
}
|
||||
|
||||
void TearDown(const ::benchmark::State& state [[maybe_unused]]) {
|
||||
}
|
||||
|
||||
ghc::filesystem::path getPath()
|
||||
{
|
||||
#ifdef __linux__
|
||||
char buf[PATH_MAX + 1];
|
||||
if (readlink("/proc/self/exe", buf, sizeof(buf) - 1) == -1)
|
||||
return {};
|
||||
std::string str { buf };
|
||||
return str.substr(0, str.rfind('/'));
|
||||
#elif _WIN32
|
||||
return ghc::filesystem::current_path();
|
||||
#endif
|
||||
}
|
||||
|
||||
std::unique_ptr<sfz::Buffer<float>> buffer;
|
||||
|
||||
ghc::filesystem::path rootPath1;
|
||||
ghc::filesystem::path rootPath2;
|
||||
};
|
||||
|
||||
|
||||
BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) {
|
||||
for (auto _ : state)
|
||||
{
|
||||
SndfileHandle sndfile(rootPath1.c_str());
|
||||
buffer = std::make_unique<sfz::Buffer<float>>(sndfile.channels() * sndfile.frames());
|
||||
sndfile.readf(buffer->data(), sndfile.frames());
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_DEFINE_F(FileFixture, DrWav)(benchmark::State& state) {
|
||||
for (auto _ : state)
|
||||
{
|
||||
drwav wav;
|
||||
if (!drwav_init_file(&wav, rootPath2.c_str(), nullptr)) {
|
||||
#ifndef NDEBUG
|
||||
std::cerr << "Can't find path" << '\n';
|
||||
#endif
|
||||
std::terminate();
|
||||
}
|
||||
buffer = std::make_unique<sfz::Buffer<float>>(wav.channels * wav.totalPCMFrameCount);
|
||||
drwav_read_pcm_frames_f32(&wav, wav.totalPCMFrameCount, buffer->data());
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_REGISTER_F(FileFixture, SndFile);
|
||||
BENCHMARK_REGISTER_F(FileFixture, DrWav);
|
||||
BENCHMARK_MAIN();
|
||||
|
|
@ -117,6 +117,10 @@ add_executable(bm_envelopes BM_envelopes.cpp ${BENCHMARK_SIMD_SOURCES})
|
|||
target_link_libraries(bm_envelopes benchmark absl::span absl::algorithm sndfile samplerate)
|
||||
target_include_directories(bm_envelopes PRIVATE ../src/sfizz ../src/external)
|
||||
|
||||
add_executable(bm_wavfile BM_wavfile.cpp ${BENCHMARK_SIMD_SOURCES})
|
||||
target_link_libraries(bm_wavfile benchmark absl::span absl::algorithm sndfile)
|
||||
target_include_directories(bm_wavfile PRIVATE ../src/sfizz ../src/external)
|
||||
|
||||
add_custom_target(sfizz_benchmarks)
|
||||
add_dependencies(sfizz_benchmarks
|
||||
bm_opf_high_vs_low
|
||||
|
|
@ -142,6 +146,8 @@ add_dependencies(sfizz_benchmarks
|
|||
bm_multiplyAdd
|
||||
bm_resample
|
||||
bm_envelopes
|
||||
bm_wavfile
|
||||
)
|
||||
|
||||
file(COPY "ride.wav" DESTINATION ${CMAKE_BINARY_DIR}/benchmarks)
|
||||
file(COPY "ride2.wav" DESTINATION ${CMAKE_BINARY_DIR}/benchmarks)
|
||||
|
|
|
|||
5358
benchmarks/dr_wav.h
Normal file
5358
benchmarks/dr_wav.h
Normal file
File diff suppressed because it is too large
Load diff
BIN
benchmarks/ride2.wav
Executable file
BIN
benchmarks/ride2.wav
Executable file
Binary file not shown.
Loading…
Add table
Reference in a new issue