Skip to content

Commit

Permalink
refined benchmark now with threading
Browse files Browse the repository at this point in the history
  • Loading branch information
faressc committed Oct 25, 2023
1 parent 316f997 commit c2e5785
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
23 changes: 18 additions & 5 deletions test/benchmark.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <benchmark/benchmark.h>
#include "../source/PluginProcessor.h"
#include "../source/PluginEditor.h"
#include "TestThread.h"
#include "utils/TestThread.h"

static void BM_PROCESSOR(benchmark::State& state) {
auto gui = juce::ScopedJuceInitialiser_GUI {};
Expand Down Expand Up @@ -43,30 +43,41 @@ BENCHMARK_DEFINE_F(InferenceFixture, BM_ONNX_INFERENCE)(benchmark::State& state)
for (auto _ : state) {
state.PauseTiming();
plugin->getInferenceThread().testPushSamples((int) state.range(0));
plugin->getInferenceThread().setBackend(ONNX);
state.ResumeTiming();
plugin->getInferenceThread().testInference(ONNX);
plugin->getInferenceThread().startThread(juce::Thread::Priority::highest);
while (plugin->getInferenceThread().isThreadRunning()){
std::this_thread::sleep_for(std::chrono::nanoseconds (10));
}
}
}

BENCHMARK_DEFINE_F(InferenceFixture, BM_LIBTORCH_INFERENCE)(benchmark::State& state) {
for (auto _ : state) {
state.PauseTiming();
plugin->getInferenceThread().testPushSamples((int) state.range(0));
plugin->getInferenceThread().setBackend(LIBTORCH);
state.ResumeTiming();
plugin->getInferenceThread().testInference(LIBTORCH);
plugin->getInferenceThread().startThread(juce::Thread::Priority::highest);
while (plugin->getInferenceThread().isThreadRunning()){
std::this_thread::sleep_for(std::chrono::nanoseconds (10));
}
}
}

BENCHMARK_DEFINE_F(InferenceFixture, BM_TFLITE_INFERENCE)(benchmark::State& state) {
for (auto _ : state) {
state.PauseTiming();
plugin->getInferenceThread().testPushSamples((int) state.range(0));
plugin->getInferenceThread().setBackend(TFLITE);
state.ResumeTiming();
plugin->getInferenceThread().testInference(TFLITE);
plugin->getInferenceThread().startThread(juce::Thread::Priority::highest);
while (plugin->getInferenceThread().isThreadRunning()){
std::this_thread::sleep_for(std::chrono::nanoseconds (10));
}
}
}


// --- Benchmarking threads ---

class ThreadFixture : public benchmark::Fixture
Expand All @@ -78,10 +89,12 @@ class ThreadFixture : public benchmark::Fixture

void SetUp(const ::benchmark::State& state) {
thread = std::make_unique<TestThread>();
std::ignore = state;
}

void TearDown(const ::benchmark::State& state) {
thread.reset();
std::ignore = state;
}
};

Expand Down
2 changes: 1 addition & 1 deletion test/TestThread.h → test/utils/TestThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestThread : public juce::Thread {
public:
TestThread() : juce::Thread("TestThread") { }

~TestThread() {
~TestThread() override {
stopThread(100);
}

Expand Down

0 comments on commit c2e5785

Please sign in to comment.