Michael Chuah / Mbed 2 deprecated Benchmark

Dependencies:   mbed

Fork of benchmark by Igor Martinovski

Files at this revision

API Documentation at this revision

Comitter:
mcx
Date:
Mon Aug 17 20:14:39 2015 +0000
Parent:
0:6d89d8c13042
Child:
2:fc68d524dd7d
Commit message:
Benchmarking code to test speed of various operations;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Dec 06 22:37:52 2010 +0000
+++ b/main.cpp	Mon Aug 17 20:14:39 2015 +0000
@@ -1,4 +1,6 @@
 #include "mbed.h"
+
+//https://developer.mbed.org/users/igor_m/code/benchmark/
 /* 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
@@ -8,16 +10,17 @@
     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 96              // Clock freqency in MHz
+#define CLOCK 100              // Clock freqency in MHz
 Timer timer;                       // Timer..
 
 Serial pc(USBTX, USBRX);
 float number_of_cycles, single_operation_time;
-volatile float a, b,c;            // Float operands and result. Must be volatile!
-//volatile int a, b,c;              // Int operands and result. Must be volatile!
+//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() {
 
@@ -27,9 +30,9 @@
 
     timer.reset();      // Reset timer
     timer.start();      // Start timer
-    pc.printf("Operations in progress.. May take some time.\n\n");
+    pc.printf("Operations in progress.. May take some time.\r\n");
     /* Determine loop overhead */
-    for (i=0; i<ITERATIONS; i++);
+    for (i=0; i<ITERATIONS; i++){}
     for_time=timer.read_us();
     timer.stop();
 
@@ -39,14 +42,18 @@
     
     /* The operation takes place in the body of
     this for loop. */
-    
-    for (i=0; i<ITERATIONS; i++) {
+    for (i=0; i<ITERATIONS; i++){
         
-        c=a+b;
-        //c=sin(a);
-        //c=sqrt(a);
+//        a = b;
+//        c = a+b;
+//        c = a*b;
+//        c = a/b;
+//        a = sqrt(b);
+//        a = log(b);
+//        a = tanh(b);
 
     }
+    
     total_time=timer.read_us();
 
     operation_time = total_time-for_time;   // Calculate the time it took for the number of operations
@@ -54,9 +61,9 @@
     single_operation_time=float(operation_time)/float(ITERATIONS);
     number_of_cycles = single_operation_time*CLOCK;
 
-    pc.printf("for overhead: \t\t%dus \n", for_time);
-    pc.printf("total time: \t\t%dus \n\n", total_time);
-    pc.printf("%d calculations took:\t%dus \n", ITERATIONS, operation_time);
-    pc.printf("single operation took: \t\t%fus\n", single_operation_time);
-    pc.printf("single operation took: \t\t%.3f cycles\n", number_of_cycles);
+    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);
 }
--- a/mbed.bld	Mon Dec 06 22:37:52 2010 +0000
+++ b/mbed.bld	Mon Aug 17 20:14:39 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e
+http://mbed.org/users/mbed_official/code/mbed/builds/b9ad9a133dc7
\ No newline at end of file