Benchmark of DP, SP and Int. Arithmetic operations for ARM Cortex M7 MCU, Nucleo-144 Stm32F746 and Stm32F767 (modified from ddown post at "Arduino for STM32") by Jovan Ivković (JovanEps)
main.cpp@2:03cf226a5ba3, 2017-01-04 (annotated)
- Committer:
- JovanEps
- Date:
- Wed Jan 04 00:04:46 2017 +0000
- Revision:
- 2:03cf226a5ba3
- Parent:
- 1:be78b18b8347
- Child:
- 3:12d9e9070739
RC1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JovanEps | 0:43b96e9650ef | 1 | //******************************************************** |
JovanEps | 0:43b96e9650ef | 2 | //** Nucleo-144 Stm32F746 and Stm32F767 benchmark ****** |
JovanEps | 0:43b96e9650ef | 3 | //** Jovan Ivkovic - 2016 ****** |
JovanEps | 0:43b96e9650ef | 4 | //******************************************************** |
JovanEps | 0:43b96e9650ef | 5 | #include "mbed.h" |
JovanEps | 0:43b96e9650ef | 6 | DigitalOut myled(LED1); |
JovanEps | 0:43b96e9650ef | 7 | Serial pc(USBTX, USBRX); |
JovanEps | 0:43b96e9650ef | 8 | Timer timer; |
JovanEps | 0:43b96e9650ef | 9 | |
JovanEps | 0:43b96e9650ef | 10 | #include <stdlib.h> |
JovanEps | 0:43b96e9650ef | 11 | #include <stdio.h> |
JovanEps | 0:43b96e9650ef | 12 | #include <string.h> |
JovanEps | 0:43b96e9650ef | 13 | #include <math.h> |
JovanEps | 0:43b96e9650ef | 14 | /* the following is optional depending on the timing function used */ |
JovanEps | 0:43b96e9650ef | 15 | #include <time.h> |
JovanEps | 0:43b96e9650ef | 16 | |
JovanEps | 0:43b96e9650ef | 17 | |
JovanEps | 2:03cf226a5ba3 | 18 | #define REDO_COMPUTATIONS 10 |
JovanEps | 2:03cf226a5ba3 | 19 | struct results { |
JovanEps | 2:03cf226a5ba3 | 20 | uint32_t doubletime; |
JovanEps | 2:03cf226a5ba3 | 21 | uint32_t floattime; |
JovanEps | 2:03cf226a5ba3 | 22 | uint32_t inttime; |
JovanEps | 2:03cf226a5ba3 | 23 | }; |
JovanEps | 0:43b96e9650ef | 24 | |
JovanEps | 2:03cf226a5ba3 | 25 | #define MAX_LOOPS 512 |
JovanEps | 2:03cf226a5ba3 | 26 | double MyDoubles[MAX_LOOPS]; |
JovanEps | 2:03cf226a5ba3 | 27 | double a_d = 12345.67, b_d = 54321.11; |
JovanEps | 2:03cf226a5ba3 | 28 | float MyFloats[MAX_LOOPS]; |
JovanEps | 2:03cf226a5ba3 | 29 | float a_f = 67890.12, b_f = 8756451.17; |
JovanEps | 2:03cf226a5ba3 | 30 | int Myints[MAX_LOOPS]; |
JovanEps | 2:03cf226a5ba3 | 31 | int a_i = 581674411, b_i = 18714; |
JovanEps | 0:43b96e9650ef | 32 | |
JovanEps | 2:03cf226a5ba3 | 33 | //**************************************** |
JovanEps | 2:03cf226a5ba3 | 34 | uint32_t micros () |
JovanEps | 2:03cf226a5ba3 | 35 | { |
JovanEps | 2:03cf226a5ba3 | 36 | //**************************************** |
JovanEps | 2:03cf226a5ba3 | 37 | // uint32_t usec = timer.read_us(); |
JovanEps | 2:03cf226a5ba3 | 38 | //return usec; |
JovanEps | 2:03cf226a5ba3 | 39 | return timer.read_us(); |
JovanEps | 2:03cf226a5ba3 | 40 | } |
JovanEps | 0:43b96e9650ef | 41 | |
JovanEps | 2:03cf226a5ba3 | 42 | //**************************************** |
JovanEps | 2:03cf226a5ba3 | 43 | void math_add (struct results *r) { |
JovanEps | 2:03cf226a5ba3 | 44 | //**************************************** |
JovanEps | 2:03cf226a5ba3 | 45 | uint32_t t, c, l; |
JovanEps | 2:03cf226a5ba3 | 46 | |
JovanEps | 2:03cf226a5ba3 | 47 | t = micros (); |
JovanEps | 2:03cf226a5ba3 | 48 | for ( c = 0 ; c < REDO_COMPUTATIONS ; c ++ ) |
JovanEps | 2:03cf226a5ba3 | 49 | { |
JovanEps | 2:03cf226a5ba3 | 50 | for ( l = 0 ; l < MAX_LOOPS ; l ++ ) |
JovanEps | 2:03cf226a5ba3 | 51 | { |
JovanEps | 2:03cf226a5ba3 | 52 | MyDoubles [ l ] = double ( a_d + b_d * double ( l ) ); |
JovanEps | 1:be78b18b8347 | 53 | } |
JovanEps | 2:03cf226a5ba3 | 54 | } |
JovanEps | 2:03cf226a5ba3 | 55 | r->doubletime = micros () - t; |
JovanEps | 0:43b96e9650ef | 56 | |
JovanEps | 2:03cf226a5ba3 | 57 | t = micros (); |
JovanEps | 2:03cf226a5ba3 | 58 | for ( c = 0 ; c < REDO_COMPUTATIONS ; c ++ ) |
JovanEps | 2:03cf226a5ba3 | 59 | { |
JovanEps | 2:03cf226a5ba3 | 60 | for ( l = 0 ; l < MAX_LOOPS ; l ++ ) |
JovanEps | 2:03cf226a5ba3 | 61 | { |
JovanEps | 2:03cf226a5ba3 | 62 | MyFloats [ l ] = float ( a_f + b_f * float ( l ) ); |
JovanEps | 0:43b96e9650ef | 63 | } |
JovanEps | 2:03cf226a5ba3 | 64 | } |
JovanEps | 2:03cf226a5ba3 | 65 | r->floattime = micros () - t; |
JovanEps | 0:43b96e9650ef | 66 | |
JovanEps | 2:03cf226a5ba3 | 67 | t = micros (); |
JovanEps | 2:03cf226a5ba3 | 68 | for ( c = 0 ; c < REDO_COMPUTATIONS ; c ++ ) |
JovanEps | 2:03cf226a5ba3 | 69 | { |
JovanEps | 2:03cf226a5ba3 | 70 | for ( l = 0 ; l < MAX_LOOPS ; l ++ ) |
JovanEps | 2:03cf226a5ba3 | 71 | { |
JovanEps | 2:03cf226a5ba3 | 72 | Myints [ l ] = a_i + b_i * l; |
JovanEps | 1:be78b18b8347 | 73 | } |
JovanEps | 2:03cf226a5ba3 | 74 | } |
JovanEps | 2:03cf226a5ba3 | 75 | r->inttime = micros () - t; |
JovanEps | 2:03cf226a5ba3 | 76 | } |
JovanEps | 0:43b96e9650ef | 77 | |
JovanEps | 2:03cf226a5ba3 | 78 | //**************************************** |
JovanEps | 2:03cf226a5ba3 | 79 | void math_sub (struct results *r) { |
JovanEps | 2:03cf226a5ba3 | 80 | //**************************************** |
JovanEps | 2:03cf226a5ba3 | 81 | uint32_t t, c, l; |
JovanEps | 2:03cf226a5ba3 | 82 | |
JovanEps | 2:03cf226a5ba3 | 83 | t = micros (); |
JovanEps | 2:03cf226a5ba3 | 84 | for ( c = 0 ; c < REDO_COMPUTATIONS ; c ++ ) |
JovanEps | 2:03cf226a5ba3 | 85 | { |
JovanEps | 2:03cf226a5ba3 | 86 | for ( l = 0 ; l < MAX_LOOPS ; l ++ ) |
JovanEps | 2:03cf226a5ba3 | 87 | { |
JovanEps | 2:03cf226a5ba3 | 88 | MyDoubles [ l ] = double ( a_d - b_d * double ( l ) ); |
JovanEps | 0:43b96e9650ef | 89 | } |
JovanEps | 2:03cf226a5ba3 | 90 | } |
JovanEps | 2:03cf226a5ba3 | 91 | r->doubletime = micros () - t; |
JovanEps | 0:43b96e9650ef | 92 | |
JovanEps | 2:03cf226a5ba3 | 93 | t = micros (); |
JovanEps | 2:03cf226a5ba3 | 94 | for ( c = 0 ; c < REDO_COMPUTATIONS ; c ++ ) |
JovanEps | 2:03cf226a5ba3 | 95 | { |
JovanEps | 2:03cf226a5ba3 | 96 | for ( l = 0 ; l < MAX_LOOPS ; l ++ ) |
JovanEps | 2:03cf226a5ba3 | 97 | { |
JovanEps | 2:03cf226a5ba3 | 98 | MyFloats [ l ] = float ( a_f - b_f * float ( l ) ); |
JovanEps | 2:03cf226a5ba3 | 99 | } |
JovanEps | 2:03cf226a5ba3 | 100 | } |
JovanEps | 2:03cf226a5ba3 | 101 | r->floattime = micros () - t; |
JovanEps | 0:43b96e9650ef | 102 | |
JovanEps | 2:03cf226a5ba3 | 103 | t = micros (); |
JovanEps | 2:03cf226a5ba3 | 104 | for ( c = 0 ; c < REDO_COMPUTATIONS ; c ++ ) |
JovanEps | 2:03cf226a5ba3 | 105 | { |
JovanEps | 2:03cf226a5ba3 | 106 | for ( l = 0 ; l < MAX_LOOPS ; l ++ ) |
JovanEps | 2:03cf226a5ba3 | 107 | { |
JovanEps | 2:03cf226a5ba3 | 108 | Myints [ l ] = a_i - b_i * l; |
JovanEps | 2:03cf226a5ba3 | 109 | } |
JovanEps | 2:03cf226a5ba3 | 110 | } |
JovanEps | 2:03cf226a5ba3 | 111 | r->inttime = micros () - t; |
JovanEps | 0:43b96e9650ef | 112 | } |
JovanEps | 0:43b96e9650ef | 113 | |
JovanEps | 2:03cf226a5ba3 | 114 | //**************************************** |
JovanEps | 2:03cf226a5ba3 | 115 | void math_mul (struct results *r) { |
JovanEps | 2:03cf226a5ba3 | 116 | //**************************************** |
JovanEps | 2:03cf226a5ba3 | 117 | uint32_t t, c, l; |
JovanEps | 2:03cf226a5ba3 | 118 | |
JovanEps | 2:03cf226a5ba3 | 119 | t = micros (); |
JovanEps | 2:03cf226a5ba3 | 120 | for ( c = 0 ; c < REDO_COMPUTATIONS ; c ++ ) |
JovanEps | 2:03cf226a5ba3 | 121 | { |
JovanEps | 2:03cf226a5ba3 | 122 | for ( l = 0 ; l < MAX_LOOPS ; l ++ ) |
JovanEps | 2:03cf226a5ba3 | 123 | { |
JovanEps | 2:03cf226a5ba3 | 124 | MyDoubles [ l ] = double ( a_d * b_d * double ( l ) ); |
JovanEps | 2:03cf226a5ba3 | 125 | } |
JovanEps | 2:03cf226a5ba3 | 126 | } |
JovanEps | 2:03cf226a5ba3 | 127 | r->doubletime = micros () - t; |
JovanEps | 0:43b96e9650ef | 128 | |
JovanEps | 2:03cf226a5ba3 | 129 | t = micros (); |
JovanEps | 2:03cf226a5ba3 | 130 | for ( c = 0 ; c < REDO_COMPUTATIONS ; c ++ ) |
JovanEps | 2:03cf226a5ba3 | 131 | { |
JovanEps | 2:03cf226a5ba3 | 132 | for ( l = 0 ; l < MAX_LOOPS ; l ++ ) |
JovanEps | 2:03cf226a5ba3 | 133 | { |
JovanEps | 2:03cf226a5ba3 | 134 | MyFloats [ l ] = float ( a_f * b_f * float ( l ) ); |
JovanEps | 2:03cf226a5ba3 | 135 | } |
JovanEps | 2:03cf226a5ba3 | 136 | } |
JovanEps | 2:03cf226a5ba3 | 137 | r->floattime = micros () - t; |
JovanEps | 0:43b96e9650ef | 138 | |
JovanEps | 2:03cf226a5ba3 | 139 | t = micros (); |
JovanEps | 2:03cf226a5ba3 | 140 | for ( c = 0 ; c < REDO_COMPUTATIONS ; c ++ ) |
JovanEps | 2:03cf226a5ba3 | 141 | { |
JovanEps | 2:03cf226a5ba3 | 142 | for ( l = 0 ; l < MAX_LOOPS ; l ++ ) |
JovanEps | 2:03cf226a5ba3 | 143 | { |
JovanEps | 2:03cf226a5ba3 | 144 | Myints [ l ] = a_i * b_i * l; |
JovanEps | 2:03cf226a5ba3 | 145 | } |
JovanEps | 2:03cf226a5ba3 | 146 | } |
JovanEps | 2:03cf226a5ba3 | 147 | r->inttime = micros () - t; |
JovanEps | 0:43b96e9650ef | 148 | } |
JovanEps | 0:43b96e9650ef | 149 | |
JovanEps | 2:03cf226a5ba3 | 150 | //**************************************** |
JovanEps | 2:03cf226a5ba3 | 151 | void math_div (struct results *r) { |
JovanEps | 2:03cf226a5ba3 | 152 | //**************************************** |
JovanEps | 2:03cf226a5ba3 | 153 | uint32_t t, c, l; |
JovanEps | 2:03cf226a5ba3 | 154 | |
JovanEps | 2:03cf226a5ba3 | 155 | t = micros (); |
JovanEps | 2:03cf226a5ba3 | 156 | for ( c = 0 ; c < REDO_COMPUTATIONS ; c ++ ) |
JovanEps | 2:03cf226a5ba3 | 157 | { |
JovanEps | 2:03cf226a5ba3 | 158 | for ( l = 0 ; l < MAX_LOOPS ; l ++ ) |
JovanEps | 2:03cf226a5ba3 | 159 | { |
JovanEps | 2:03cf226a5ba3 | 160 | MyDoubles [ l ] = double ( a_d / b_d * double ( l ) ); |
JovanEps | 2:03cf226a5ba3 | 161 | } |
JovanEps | 2:03cf226a5ba3 | 162 | } |
JovanEps | 2:03cf226a5ba3 | 163 | r->doubletime = micros () - t; |
JovanEps | 2:03cf226a5ba3 | 164 | |
JovanEps | 2:03cf226a5ba3 | 165 | t = micros (); |
JovanEps | 2:03cf226a5ba3 | 166 | for ( c = 0 ; c < REDO_COMPUTATIONS ; c ++ ) |
JovanEps | 2:03cf226a5ba3 | 167 | { |
JovanEps | 2:03cf226a5ba3 | 168 | for ( l = 0 ; l < MAX_LOOPS ; l ++ ) |
JovanEps | 2:03cf226a5ba3 | 169 | { |
JovanEps | 2:03cf226a5ba3 | 170 | MyFloats [ l ] = float ( a_f / b_f * float ( l ) ); |
JovanEps | 2:03cf226a5ba3 | 171 | } |
JovanEps | 2:03cf226a5ba3 | 172 | } |
JovanEps | 2:03cf226a5ba3 | 173 | r->floattime = micros () - t; |
JovanEps | 2:03cf226a5ba3 | 174 | |
JovanEps | 2:03cf226a5ba3 | 175 | t = micros (); |
JovanEps | 2:03cf226a5ba3 | 176 | for ( c = 0 ; c < REDO_COMPUTATIONS ; c ++ ) |
JovanEps | 2:03cf226a5ba3 | 177 | { |
JovanEps | 2:03cf226a5ba3 | 178 | for ( l = 0 ; l < MAX_LOOPS ; l ++ ) |
JovanEps | 2:03cf226a5ba3 | 179 | { |
JovanEps | 2:03cf226a5ba3 | 180 | Myints [ l ] = a_i / b_i * l; |
JovanEps | 2:03cf226a5ba3 | 181 | } |
JovanEps | 2:03cf226a5ba3 | 182 | } |
JovanEps | 2:03cf226a5ba3 | 183 | r->inttime = micros () - t; |
JovanEps | 0:43b96e9650ef | 184 | } |
JovanEps | 0:43b96e9650ef | 185 | |
JovanEps | 2:03cf226a5ba3 | 186 | //**************************************** |
JovanEps | 2:03cf226a5ba3 | 187 | void bench_loop() { |
JovanEps | 2:03cf226a5ba3 | 188 | //**************************************** |
JovanEps | 2:03cf226a5ba3 | 189 | |
JovanEps | 2:03cf226a5ba3 | 190 | struct results add_ops, sub_ops, mul_ops, div_ops; |
JovanEps | 2:03cf226a5ba3 | 191 | |
JovanEps | 2:03cf226a5ba3 | 192 | math_add(&add_ops); |
JovanEps | 2:03cf226a5ba3 | 193 | math_sub(&sub_ops); |
JovanEps | 2:03cf226a5ba3 | 194 | math_mul(&mul_ops); |
JovanEps | 2:03cf226a5ba3 | 195 | math_div(&div_ops); |
JovanEps | 0:43b96e9650ef | 196 | |
JovanEps | 2:03cf226a5ba3 | 197 | pc.printf("\n\n"); |
JovanEps | 2:03cf226a5ba3 | 198 | pc.printf("\n FUNCTION DOUBLE SINGLE INT"); |
JovanEps | 2:03cf226a5ba3 | 199 | |
JovanEps | 2:03cf226a5ba3 | 200 | pc.printf("\n Time - ADD (us/512) :\t "); |
JovanEps | 2:03cf226a5ba3 | 201 | pc.printf( "%0.1f", ( float ) add_ops.doubletime / REDO_COMPUTATIONS ); |
JovanEps | 2:03cf226a5ba3 | 202 | pc.printf("\t\t"); |
JovanEps | 2:03cf226a5ba3 | 203 | pc.printf( "%0.1f", ( float ) add_ops.floattime / REDO_COMPUTATIONS ); |
JovanEps | 2:03cf226a5ba3 | 204 | pc.printf("\t\t"); |
JovanEps | 2:03cf226a5ba3 | 205 | pc.printf("%0.1f", ( float ) add_ops.inttime / REDO_COMPUTATIONS ); |
JovanEps | 2:03cf226a5ba3 | 206 | pc.printf("\n"); |
JovanEps | 2:03cf226a5ba3 | 207 | |
JovanEps | 2:03cf226a5ba3 | 208 | pc.printf("\n Time - SUB (us/512) :\t "); |
JovanEps | 2:03cf226a5ba3 | 209 | pc.printf( "%0.1f", ( float ) sub_ops.doubletime / REDO_COMPUTATIONS ); |
JovanEps | 2:03cf226a5ba3 | 210 | pc.printf("\t\t"); |
JovanEps | 2:03cf226a5ba3 | 211 | pc.printf( "%0.1f", ( float ) sub_ops.floattime / REDO_COMPUTATIONS ); |
JovanEps | 2:03cf226a5ba3 | 212 | pc.printf("\t\t"); |
JovanEps | 2:03cf226a5ba3 | 213 | pc.printf( "%0.1f", ( float ) sub_ops.inttime / REDO_COMPUTATIONS ); |
JovanEps | 2:03cf226a5ba3 | 214 | pc.printf("\n"); |
JovanEps | 0:43b96e9650ef | 215 | |
JovanEps | 2:03cf226a5ba3 | 216 | pc.printf("\n Time - MUL (us/512) :\t "); |
JovanEps | 2:03cf226a5ba3 | 217 | pc.printf( "%0.1f", ( float ) mul_ops.doubletime / REDO_COMPUTATIONS ); |
JovanEps | 2:03cf226a5ba3 | 218 | pc.printf("\t\t"); |
JovanEps | 2:03cf226a5ba3 | 219 | pc.printf( "%0.1f", ( float ) mul_ops.floattime / REDO_COMPUTATIONS ); |
JovanEps | 2:03cf226a5ba3 | 220 | pc.printf("\t\t"); |
JovanEps | 2:03cf226a5ba3 | 221 | pc.printf( "%0.1f", ( float ) mul_ops.inttime / REDO_COMPUTATIONS ); |
JovanEps | 2:03cf226a5ba3 | 222 | pc.printf("\n"); |
JovanEps | 2:03cf226a5ba3 | 223 | |
JovanEps | 2:03cf226a5ba3 | 224 | pc.printf("\n Time - DIV (us/512) :\t "); |
JovanEps | 2:03cf226a5ba3 | 225 | pc.printf( "%0.1f", ( float ) div_ops.doubletime / REDO_COMPUTATIONS ); |
JovanEps | 2:03cf226a5ba3 | 226 | pc.printf("\t\t"); |
JovanEps | 2:03cf226a5ba3 | 227 | pc.printf( "%0.1f", ( float ) div_ops.floattime / REDO_COMPUTATIONS ); |
JovanEps | 2:03cf226a5ba3 | 228 | pc.printf("\t\t"); |
JovanEps | 2:03cf226a5ba3 | 229 | pc.printf( "%0.1f", ( float ) div_ops.inttime / REDO_COMPUTATIONS ); |
JovanEps | 2:03cf226a5ba3 | 230 | pc.printf("\n"); |
JovanEps | 2:03cf226a5ba3 | 231 | |
JovanEps | 2:03cf226a5ba3 | 232 | wait(1); |
JovanEps | 0:43b96e9650ef | 233 | } |
JovanEps | 0:43b96e9650ef | 234 | |
JovanEps | 1:be78b18b8347 | 235 | //********************************* |
JovanEps | 1:be78b18b8347 | 236 | //** MAIN block ** |
JovanEps | 1:be78b18b8347 | 237 | //********************************* |
JovanEps | 1:be78b18b8347 | 238 | int main() |
JovanEps | 1:be78b18b8347 | 239 | { |
JovanEps | 2:03cf226a5ba3 | 240 | pc.baud(57600); |
JovanEps | 0:43b96e9650ef | 241 | |
JovanEps | 2:03cf226a5ba3 | 242 | pc.printf("\n My Benchamrk ..."); |
JovanEps | 2:03cf226a5ba3 | 243 | pc.printf("Beginningbenchmark at "); |
JovanEps | 2:03cf226a5ba3 | 244 | pc.printf("default 216 MHz ...\n"); |
JovanEps | 2:03cf226a5ba3 | 245 | pc.printf("\n\n"); |
JovanEps | 2:03cf226a5ba3 | 246 | |
JovanEps | 1:be78b18b8347 | 247 | while(1) |
JovanEps | 1:be78b18b8347 | 248 | { |
JovanEps | 2:03cf226a5ba3 | 249 | myled=1; |
JovanEps | 2:03cf226a5ba3 | 250 | timer.start(); |
JovanEps | 2:03cf226a5ba3 | 251 | |
JovanEps | 2:03cf226a5ba3 | 252 | bench_loop(); //Call of banch method |
JovanEps | 2:03cf226a5ba3 | 253 | |
JovanEps | 2:03cf226a5ba3 | 254 | pc.printf(" kraj \n"); |
JovanEps | 2:03cf226a5ba3 | 255 | myled=0; |
JovanEps | 2:03cf226a5ba3 | 256 | timer.stop(); |
JovanEps | 2:03cf226a5ba3 | 257 | |
JovanEps | 1:be78b18b8347 | 258 | } |
JovanEps | 0:43b96e9650ef | 259 | } |