Skip to content

Commit

Permalink
Add a benchmark for the C++ version of CARFAC.
Browse files Browse the repository at this point in the history
Test a sinusoidal audio input on 22.05khz input, with various time lengths tested.

Test with enforced number of threads in parallel, between 1 and 128.

PiperOrigin-RevId: 633416924
  • Loading branch information
Rob Schonberger authored and copybara-github committed May 14, 2024
1 parent 2fefe74 commit aa105fa
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions cpp/carfac_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "carfac.h"

#include <cmath>
#include <string>
#include <vector>

#include "benchmark/benchmark.h"
#include "gtest/gtest.h"

#include "agc.h"
#include "car.h"
#include "carfac.h"
#include "common.h"
#include "ear.h"
#include "ihc.h"
Expand Down Expand Up @@ -296,3 +297,33 @@ TEST_F(CARFACTest, AGCDesignAtLowSampleRate) {
}
}
}

void BM_CarfacSegment(benchmark::State& state) {
const auto segment_length_samples = state.range(0);
const int num_ears = 1;
const FPType sample_rate = 22050.0;
CARParams car_params;
IHCParams ihc_params;
AGCParams agc_params;
CARFAC carfac(num_ears, sample_rate, car_params, ihc_params, agc_params);
// Sinusoid input.
const float kFrequency = 500.0; // Hz.
ArrayXX sound_data(num_ears, segment_length_samples);
sound_data.row(0) =
ArrayX::LinSpaced(segment_length_samples, 0.0, 2 * kFrequency * M_PI)
.sin();

const bool open_loop = false;
for (auto s : state) {
// store everything for the benchmarks.
CARFACOutput output(true, true, true, true);
carfac.RunSegment(sound_data, open_loop, &output);
}
}

BENCHMARK(BM_CarfacSegment)->ThreadRange(1, 128)
->Arg(220)
->Arg(2205)
->Arg(22050)
->Arg(44100)
->Arg(220500);

0 comments on commit aa105fa

Please sign in to comment.