Skip to content

Instantly share code, notes, and snippets.

@creaktive
Created April 1, 2022 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creaktive/5e9c34466287bc8553b1472f1fdf25ae to your computer and use it in GitHub Desktop.
Save creaktive/5e9c34466287bc8553b1472f1fdf25ae to your computer and use it in GitHub Desktop.
pianolizer benchmark
/*
* wget https://github.com/creaktive/pianolizer/raw/master/cpp/pianolizer.hpp
* g++ -Ofast -std=c++14 -o benchmark benchmark.cpp
*/
#include <chrono>
#include <iostream>
#include <stdlib.h>
#include "pianolizer.hpp"
using namespace std;
int main() {
const unsigned SAMPLE_RATE = 44100;
auto sdft = SlidingDFT(make_shared<PianoTuning>(SAMPLE_RATE), -1.);
const unsigned bufferSize = 128;
float input[bufferSize];
const float *output = nullptr;
auto start = chrono::high_resolution_clock::now();
unsigned i;
for (i = 0; i < bufferSize * 10000; i++) {
unsigned j = i % bufferSize;
input[j] = ((i % 100) / 50.) - 1.;
if (j == bufferSize - 1)
output = sdft.process(input, bufferSize, .05);
}
auto end = chrono::high_resolution_clock::now();
chrono::duration<double> elapsed = end - start;
cerr << "# benchmark: " << static_cast<int>(round(i / elapsed.count())) << " samples per second" << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment