test

Dependencies:   mbed

Fork of benchmarks for F303RE by pawel wzietek

Committer:
pawlps
Date:
Sat Jun 06 15:24:34 2015 +0000
Revision:
0:08bd44467cf7
some simple benchmarks used to compare  KL25Z and F303RE
;
;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pawlps 0:08bd44467cf7 1 #include "mbed.h"
pawlps 0:08bd44467cf7 2
pawlps 0:08bd44467cf7 3 //simple benchmark, see main for results
pawlps 0:08bd44467cf7 4
pawlps 0:08bd44467cf7 5 DigitalOut led(LED1);
pawlps 0:08bd44467cf7 6
pawlps 0:08bd44467cf7 7
pawlps 0:08bd44467cf7 8 AnalogIn Ain(A0);
pawlps 0:08bd44467cf7 9
pawlps 0:08bd44467cf7 10
pawlps 0:08bd44467cf7 11 Serial pc(USBTX, USBRX); // tx, rx
pawlps 0:08bd44467cf7 12
pawlps 0:08bd44467cf7 13 Timer Tim, Timc;
pawlps 0:08bd44467cf7 14 int dt;
pawlps 0:08bd44467cf7 15 float dtavg;
pawlps 0:08bd44467cf7 16
pawlps 0:08bd44467cf7 17
pawlps 0:08bd44467cf7 18 #define Nsamp 2000
pawlps 0:08bd44467cf7 19 unsigned short samples[Nsamp]; //analogin sample table
pawlps 0:08bd44467cf7 20
pawlps 0:08bd44467cf7 21 volatile float x,s; //volatile to prevent compiler from optimizing loops
pawlps 0:08bd44467cf7 22 volatile float y;
pawlps 0:08bd44467cf7 23
pawlps 0:08bd44467cf7 24 volatile double dx, ds;
pawlps 0:08bd44467cf7 25 volatile double dy;
pawlps 0:08bd44467cf7 26
pawlps 0:08bd44467cf7 27 volatile long ix,iy,is;
pawlps 0:08bd44467cf7 28
pawlps 0:08bd44467cf7 29 //************************
pawlps 0:08bd44467cf7 30 inline void test_acq()
pawlps 0:08bd44467cf7 31 {
pawlps 0:08bd44467cf7 32 int N=Nsamp;
pawlps 0:08bd44467cf7 33 register int i;
pawlps 0:08bd44467cf7 34 Tim.reset(); Tim.start();
pawlps 0:08bd44467cf7 35 for(i=0; i<N; i++) {
pawlps 0:08bd44467cf7 36 samples[i] = Ain.read_u16();
pawlps 0:08bd44467cf7 37 }
pawlps 0:08bd44467cf7 38 Tim.stop();
pawlps 0:08bd44467cf7 39 dt=Tim.read_us();
pawlps 0:08bd44467cf7 40 dtavg=dt/(float) Nsamp;
pawlps 0:08bd44467cf7 41 pc.printf(" input of %d values: total %d, avg: %f \r\n",N, dt, dtavg);
pawlps 0:08bd44467cf7 42
pawlps 0:08bd44467cf7 43 }
pawlps 0:08bd44467cf7 44
pawlps 0:08bd44467cf7 45
pawlps 0:08bd44467cf7 46
pawlps 0:08bd44467cf7 47 inline void testmullong()
pawlps 0:08bd44467cf7 48 {
pawlps 0:08bd44467cf7 49 int N=100000;
pawlps 0:08bd44467cf7 50
pawlps 0:08bd44467cf7 51 x=Timc.read_ms(); y=Timc.read_ms();
pawlps 0:08bd44467cf7 52 Tim.reset(); Tim.start();
pawlps 0:08bd44467cf7 53 Timc.start();
pawlps 0:08bd44467cf7 54
pawlps 0:08bd44467cf7 55 for(int i=0; i<N; i++) {
pawlps 0:08bd44467cf7 56 is=is+ix*iy;
pawlps 0:08bd44467cf7 57 }
pawlps 0:08bd44467cf7 58 Tim.stop();
pawlps 0:08bd44467cf7 59 dt=Tim.read_us();
pawlps 0:08bd44467cf7 60 dtavg=dt/(float)N;
pawlps 0:08bd44467cf7 61 pc.printf(" add-mult of %d longs: total %d, avg: %f \r\n", N, dt, dtavg);
pawlps 0:08bd44467cf7 62
pawlps 0:08bd44467cf7 63 }
pawlps 0:08bd44467cf7 64
pawlps 0:08bd44467cf7 65
pawlps 0:08bd44467cf7 66 inline void testmulfloat()
pawlps 0:08bd44467cf7 67 {
pawlps 0:08bd44467cf7 68 int N=100000;
pawlps 0:08bd44467cf7 69
pawlps 0:08bd44467cf7 70 x=Timc; y=Timc;
pawlps 0:08bd44467cf7 71 Tim.reset(); Tim.start();
pawlps 0:08bd44467cf7 72
pawlps 0:08bd44467cf7 73
pawlps 0:08bd44467cf7 74 for(int i=0; i<N; i++) {
pawlps 0:08bd44467cf7 75 s=s+x*y;
pawlps 0:08bd44467cf7 76 }
pawlps 0:08bd44467cf7 77 Tim.stop();
pawlps 0:08bd44467cf7 78 dt=Tim.read_us();
pawlps 0:08bd44467cf7 79 dtavg=dt/(float)N;
pawlps 0:08bd44467cf7 80 pc.printf(" add-mult of %d floats: total %d, avg: %f \r\n", N, dt, dtavg);
pawlps 0:08bd44467cf7 81
pawlps 0:08bd44467cf7 82 }
pawlps 0:08bd44467cf7 83
pawlps 0:08bd44467cf7 84
pawlps 0:08bd44467cf7 85 inline void testdivfloat()
pawlps 0:08bd44467cf7 86 {
pawlps 0:08bd44467cf7 87 int N=100000;
pawlps 0:08bd44467cf7 88
pawlps 0:08bd44467cf7 89 x=Timc; y=Timc;
pawlps 0:08bd44467cf7 90 Tim.reset(); Tim.start();
pawlps 0:08bd44467cf7 91
pawlps 0:08bd44467cf7 92
pawlps 0:08bd44467cf7 93 for(int i=0; i<N; i++) {
pawlps 0:08bd44467cf7 94 s=s+x/y;
pawlps 0:08bd44467cf7 95 }
pawlps 0:08bd44467cf7 96 Tim.stop();
pawlps 0:08bd44467cf7 97 dt=Tim.read_us();
pawlps 0:08bd44467cf7 98 dtavg=dt/(float)N;
pawlps 0:08bd44467cf7 99 pc.printf(" add-div of %d floats: total %d, avg: %f \r\n", N, dt, dtavg);
pawlps 0:08bd44467cf7 100
pawlps 0:08bd44467cf7 101 }
pawlps 0:08bd44467cf7 102
pawlps 0:08bd44467cf7 103
pawlps 0:08bd44467cf7 104 inline void testsin()
pawlps 0:08bd44467cf7 105 {
pawlps 0:08bd44467cf7 106 int N=10000;
pawlps 0:08bd44467cf7 107
pawlps 0:08bd44467cf7 108 x=Timc;
pawlps 0:08bd44467cf7 109 Tim.reset(); Tim.start();
pawlps 0:08bd44467cf7 110
pawlps 0:08bd44467cf7 111
pawlps 0:08bd44467cf7 112 for(int i=0; i<N; i++) {
pawlps 0:08bd44467cf7 113 s=s+sin(x);
pawlps 0:08bd44467cf7 114 }
pawlps 0:08bd44467cf7 115 Tim.stop();
pawlps 0:08bd44467cf7 116 dt=Tim.read_us();
pawlps 0:08bd44467cf7 117 dtavg=dt/(float)N;
pawlps 0:08bd44467cf7 118 pc.printf(" add-sin of %d floats: total %d, avg: %f \r\n", N, dt, dtavg);
pawlps 0:08bd44467cf7 119
pawlps 0:08bd44467cf7 120 }
pawlps 0:08bd44467cf7 121
pawlps 0:08bd44467cf7 122
pawlps 0:08bd44467cf7 123 inline void testmuldouble()
pawlps 0:08bd44467cf7 124 {
pawlps 0:08bd44467cf7 125 int N=100000;
pawlps 0:08bd44467cf7 126
pawlps 0:08bd44467cf7 127 dx=Timc; dy=Timc;
pawlps 0:08bd44467cf7 128 Tim.reset(); Tim.start();
pawlps 0:08bd44467cf7 129
pawlps 0:08bd44467cf7 130 for(int i=0; i<N; i++) {
pawlps 0:08bd44467cf7 131 ds=ds+dx*dy;
pawlps 0:08bd44467cf7 132 }
pawlps 0:08bd44467cf7 133 Tim.stop();
pawlps 0:08bd44467cf7 134 dt=Tim.read_us();
pawlps 0:08bd44467cf7 135 dtavg=dt/(float)N;
pawlps 0:08bd44467cf7 136 pc.printf(" add-mult of %d doubles: total %d, avg: %f \r\n", N, dt, dtavg);
pawlps 0:08bd44467cf7 137
pawlps 0:08bd44467cf7 138 }
pawlps 0:08bd44467cf7 139
pawlps 0:08bd44467cf7 140
pawlps 0:08bd44467cf7 141 inline void testdivdouble()
pawlps 0:08bd44467cf7 142 {
pawlps 0:08bd44467cf7 143 int N=100000;
pawlps 0:08bd44467cf7 144
pawlps 0:08bd44467cf7 145 dx=Timc; dy=Timc;
pawlps 0:08bd44467cf7 146 Tim.reset(); Tim.start();
pawlps 0:08bd44467cf7 147
pawlps 0:08bd44467cf7 148 for(int i=0; i<N; i++) {
pawlps 0:08bd44467cf7 149 ds=ds+dx/dy;
pawlps 0:08bd44467cf7 150 }
pawlps 0:08bd44467cf7 151 Tim.stop();
pawlps 0:08bd44467cf7 152 dt=Tim.read_us();
pawlps 0:08bd44467cf7 153 dtavg=dt/(float)N;
pawlps 0:08bd44467cf7 154 pc.printf("add-div of %d doubles: total %d, avg: %f \r\n", N, dt, dtavg);
pawlps 0:08bd44467cf7 155
pawlps 0:08bd44467cf7 156 }
pawlps 0:08bd44467cf7 157
pawlps 0:08bd44467cf7 158
pawlps 0:08bd44467cf7 159
pawlps 0:08bd44467cf7 160 //**********************
pawlps 0:08bd44467cf7 161
pawlps 0:08bd44467cf7 162 int main() {
pawlps 0:08bd44467cf7 163
pawlps 0:08bd44467cf7 164
pawlps 0:08bd44467cf7 165 //pc.baud(115200); //set terminal to 115200 baud
pawlps 0:08bd44467cf7 166
pawlps 0:08bd44467cf7 167 pc.printf("start\n");
pawlps 0:08bd44467cf7 168
pawlps 0:08bd44467cf7 169 Tim.reset();
pawlps 0:08bd44467cf7 170 led=0;
pawlps 0:08bd44467cf7 171
pawlps 0:08bd44467cf7 172 while(1)
pawlps 0:08bd44467cf7 173 {
pawlps 0:08bd44467cf7 174 led = 1-led;
pawlps 0:08bd44467cf7 175 pc.printf("\n\n ");
pawlps 0:08bd44467cf7 176 test_acq(); //KL25z: 32.6us per loop; F303RE: 8.1us per loop
pawlps 0:08bd44467cf7 177 testmullong(); //KL25z: 0.25 F303RE: 0.132
pawlps 0:08bd44467cf7 178 testmulfloat(); //KL25z: 2.61 F303RE: 0.187
pawlps 0:08bd44467cf7 179 testdivfloat(); // KL25z: 3.68 F303RE: 0.35
pawlps 0:08bd44467cf7 180 testsin(); //KL25z: 13.6 F303RE: 1.57
pawlps 0:08bd44467cf7 181 testmuldouble(); //KL25z: 8.44 F303RE: 6.84
pawlps 0:08bd44467cf7 182 testdivdouble(); //KL25z: 13.7 F303RE: 17.5
pawlps 0:08bd44467cf7 183
pawlps 0:08bd44467cf7 184 wait(1);
pawlps 0:08bd44467cf7 185 }
pawlps 0:08bd44467cf7 186
pawlps 0:08bd44467cf7 187 }