Skip to content

Instantly share code, notes, and snippets.

@giuliomoro
Last active May 21, 2021 07:37
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 giuliomoro/e0cb86aab32154555fc61867362bef51 to your computer and use it in GitHub Desktop.
Save giuliomoro/e0cb86aab32154555fc61867362bef51 to your computer and use it in GitHub Desktop.
Bela: Compute CPU time for render()
#include <Bela.h>
#include <chrono>
bool setup(BelaContext* context, void* userArg)
{
// your initialisation code goes here
// ...
auto start = std::chrono::steady_clock::now();
unsigned int times = 10000;
for(unsigned int n = 0; n < times; ++n)
render(context, userArg);
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> elapsedSeconds = end - start;
double secondsPerIteration = elapsedSeconds.count()/(double)times;
printf("It took %.4fs to run %u iterations (%f ms per iteration)\n", elapsedSeconds.count(), times, secondsPerIteration * 1000);
// now you can return true if you want to run the audio processing, or false if you want to stop here
return false;
}
void render(BelaContext* context, void* userArg)
{
// your code here
}
void cleanup(BelaContext* context, void* userArg)
{
// your code here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment