Last active
May 21, 2021 07:37
-
-
Save giuliomoro/e0cb86aab32154555fc61867362bef51 to your computer and use it in GitHub Desktop.
Bela: Compute CPU time for render()
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
#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