Skip to content

Instantly share code, notes, and snippets.

@agners
Forked from mlubin/newton.jl
Last active May 24, 2017 04:42
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 agners/daa7b0c39d6e511f5f0780a6e860af0d to your computer and use it in GitHub Desktop.
Save agners/daa7b0c39d6e511f5f0780a6e860af0d to your computer and use it in GitHub Desktop.
i.MX 7 Cortex-M4 FreeRTOS C micro benchmark
#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