-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0201fb
commit 8843cb2
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FetchContent_Declare( | ||
nanobench | ||
GIT_REPOSITORY https://github.com/martinus/nanobench.git | ||
GIT_TAG v4.1.0 | ||
GIT_SHALLOW TRUE) | ||
|
||
FetchContent_Declare( | ||
doctest | ||
GIT_REPOSITORY https://github.com/doctest/doctest.git | ||
GIT_TAG v2.4.11 | ||
GIT_SHALLOW TRUE) | ||
|
||
FetchContent_MakeAvailable(nanobench doctest) | ||
|
||
add_executable(perf_tests perf_tests.cpp basicosc_perf.cpp) | ||
target_include_directories(perf_tests PRIVATE ${doctest_SOURCE_DIR}/doctest) | ||
target_link_libraries(perf_tests PRIVATE nanobench dsp doctest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "doctest.h" | ||
#include "nanobench.h" | ||
#include <chrono> | ||
|
||
#include "basic_oscillators.h" | ||
|
||
using namespace ankerl; | ||
using namespace std::chrono_literals; | ||
|
||
constexpr size_t kSamplerate = 48000; | ||
constexpr size_t kOutputSize = kSamplerate * 5; | ||
constexpr float kFreq = 750; | ||
constexpr size_t kBlockSize = 512; | ||
|
||
// Render 5 second of audio | ||
TEST_CASE("Sine") | ||
{ | ||
sfdsp::BasicOscillator osc; | ||
osc.Init(kSamplerate, kFreq, sfdsp::OscillatorType::Sine); | ||
auto out = std::make_unique<float[]>(kOutputSize); | ||
|
||
nanobench::Bench bench; | ||
bench.title("BasicOscillator (Sine)"); | ||
bench.relative(true); | ||
bench.minEpochIterations(5); | ||
bench.timeUnit(1ms, "ms"); | ||
|
||
bench.run("BasicOscillator::ProcessBlock (Sine)", [&]() { | ||
const size_t block_count = kOutputSize / kBlockSize; | ||
float* write_ptr = out.get(); | ||
for (size_t i = 0; i < block_count; ++i) | ||
{ | ||
osc.ProcessBlock(write_ptr, kBlockSize); | ||
write_ptr += kBlockSize; | ||
} | ||
|
||
// Process reminder | ||
const size_t reminder = kOutputSize % kBlockSize; | ||
osc.ProcessBlock(write_ptr, reminder); | ||
}); | ||
|
||
sfdsp::BasicOscillator osc2; | ||
osc2.Init(kSamplerate, kFreq, sfdsp::OscillatorType::Sine); | ||
|
||
bench.run("BasicOscillator::Tick (Sine)", [&]() { | ||
for (auto i = 0; i < kOutputSize; ++i) | ||
out[i] = osc2.Tick(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN | ||
#include "doctest.h" |