-
-
Save agners/daa7b0c39d6e511f5f0780a6e860af0d to your computer and use it in GitHub Desktop.
i.MX 7 Cortex-M4 FreeRTOS C micro benchmark
This file contains hidden or 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 <math.h> | |
#include "FreeRTOS.h" | |
#include "task.h" | |
#include "board.h" | |
#include "debug_console_imx.h" | |
double squareroot(double x) | |
{ | |
double it = x; | |
while (fabs(it*it - x) > 1e-13) { | |
it = it - (it*it-x)/(2*it); | |
} | |
return it; | |
} | |
void benchmark(void) | |
{ | |
const int num_iter = 1000; | |
TickType_t t = xTaskGetTickCount(); | |
volatile double sum_real = 0; | |
for (int i = 0; i < num_iter; i++) { | |
sum_real += squareroot(10000.0); | |
} | |
TickType_t ttot = xTaskGetTickCount() - t; | |
PRINTF("%d milliseconds\n\r", ttot); | |
} | |
void BenchmarkTask(void *pvParameters) | |
{ | |
PRINTF("\r\nBenchmark!\n\n\r"); | |
while(1) | |
{ | |
benchmark(); | |
} | |
} | |
int main(void) | |
{ | |
// Initialize demo application pins setting and clock setting. | |
hardware_init(); | |
// Create a demo task which will print Hello world and echo user's input. | |
xTaskCreate(BenchmarkTask, "Benchmark Task", configMINIMAL_STACK_SIZE, | |
NULL, tskIDLE_PRIORITY+1, NULL); | |
// Start FreeRTOS scheduler. | |
vTaskStartScheduler(); | |
// Should never reach this point. | |
while (true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment