Benchmarking test code for various operations

Dependencies:   mbed

Fork of benchmark by Igor Martinovski

Benchmarking the performance of various mbed boards that I have

Using the excellent code by Igor, I have benchmarked the performance of the following platforms:

The data can be found in this link:

For the hyperbolic tan (tanh) function, I made a graph showing how the clock speed of various ARM Cortex-M4 boards with FPU affects the computation time in microseconds. Computation Time - tanh



File content as of revision 3:ec2e20a9bd03:

#include "mbed.h"

/* This program determines the time it takes to perform floating point
    and integer operations.
    To determine the time it takes, a Timer is used to measure the time
    it takes to complete a large amount of iterations. The time for a single
    operation can then be determined.

    To increase accuracy of the results, an empty for loop is timed to determine
    the loop overhead and the overhead is subtracted from the time it takes to
    complete the operation loop.

#define ITERATIONS 1000000    // Number of calculations.
#define CLOCK 64              // Clock freqency in MHz
Timer timer;                       // Timer..

Serial pc(USBTX, USBRX);
float number_of_cycles, single_operation_time;
//volatile int a, b, c;              // Int operands and result. Must be volatile!
volatile float a, b, c;            // Float operands and result. Must be volatile!
//volatile double a, b, c;            // Float operands and result. Must be volatile!

int main() {

    // Apparently I'm not getting full speed!? 
    printf("SystemCoreClock = %d MHz\r\n", SystemCoreClock/1000000);
    // Need external crystal to make it run faster?

    unsigned int i, for_time, total_time, operation_time;

    timer.reset();      // Reset timer
    timer.start();      // Start timer
    pc.printf("Operations in progress.. May take some time.\r\n");
    /* Determine loop overhead */
    for (i=0; i<ITERATIONS; i++){}

    /* Determine the total loop time */
    /* The operation takes place in the body of
    this for loop. */
    for (i=0; i<ITERATIONS; i++){
//        a = b;
//        c = a+b;
//        c = a*b;
//        c = a/b;
//        a = sqrt(b);
//        a = log(b);
//        a = tanh(b);
//        a = (10*pow(b,3) + 105*b)/(pow(b,4) + 45*pow(b,2) + 105);
        a = (10*b*b*b + 105*b)/(b*b*b*b + 45* + 105);

    operation_time = total_time-for_time;   // Calculate the time it took for the number of operations

    number_of_cycles = single_operation_time*CLOCK;

    pc.printf("for overhead: \t\t%dus \r\n", for_time);
    pc.printf("total time: \t\t%dus \r\n", total_time);
    pc.printf("%d calculations took:\t%dus \r\n", ITERATIONS, operation_time);
    pc.printf("single operation took: \t\t%fus \r\n", single_operation_time);
    pc.printf("single operation took: \t\t%.3f cycles \r\n", number_of_cycles);