rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
rfi_perftest.cpp
Go to the documentation of this file.
1/**
2 * @file rfi_perftest.cpp
3 *
4 * Method execution time micro test.
5 *
6 * @date Nov 30, 2012
7 * @author Andrey Belomutskiy, (c) 2012-2020
8 */
9
10#include "pch.h"
11#include "rfi_perftest.h"
12#include "fuel_math.h"
13
14#include "eficonsole.h"
15#include "time.h"
16
17#include "console_io.h"
18
19#if EFI_PERF_METRICS
20#include "test.h"
21
22static void testSystemCalls(const int count) {
23 time_t start, time;
24 long result = 0;
25
26 start = getTimeNowMs();
27 for (int i = 0; i < count / 2; i++) {
28// setPinValue(&testOutput, 0);
29// setPinValue(&testOutput, 1);
30 }
31
32 time = getTimeNowMs() - start;
33 // Finished 100000 iterations of 'setPinValue()' in 120ms
34// prin("Finished %d iterations of 'setPinValue()' in %dms\r\n", count, time);
35
36 start = getTimeNowMs();
37 for (int i = 0; i < count; i++)
38 result += chTimeNow();
39 time = getTimeNowMs() - start;
40 if (result != 0) {
41 // Finished 100000 iterations of 'chTimeNow()' in 33ms
42 efiPrintf("Finished %d iterations of 'chTimeNow()' in %dms", count, time);
43 }
44
45 start = getTimeNowMs();
46 for (int i = 0; i < count; i++) {
47 chSysLock()
48 ;
49 result += chTimeNow();
50 chSysUnlock()
51 ;
52 }
53 time = getTimeNowMs() - start;
54 if (result != 0) {
55 // Finished 100000 iterations of 'chTimeNow()' with chSysLock in 144ms
56 efiPrintf("Finished %d iterations of 'chTimeNow()' with chSysLock in %dms", count, time);
57 }
58
59 start = getTimeNowMs();
60 for (int i = 0; i < count; i++)
61 result += getTimeNowMs();
62 time = getTimeNowMs() - start;
63 if (result != 0)
64 efiPrintf("Finished %d iterations of 'getTimeNowMs' in %dms", count, time);
65}
66
68
69static void testRusefiMethods(const int count) {
70 time_t start, time;
71 int tempi = 1;
72
73 start = getTimeNowMs();
74
75 time = getTimeNowMs() - start;
76 if (tempi != 0)
77 efiPrintf("Finished %d iterations of getBaseFuel in %dms", count, time);
78
79// start = getTimeNowMs();
80// for (int i = 0; i < count; i++)
81// tempi += getInjectionDuration(1200, NULL); // todo
82// time = getTimeNowMs() - start;
83// if (tempi != 0)
84// efiPrintf("Finished %d iterations of getFuelMs in %dms", count, time);
85
86 start = getTimeNowMs();
87 for (int i = 0; i < count; i++) {
89 tempi += testEngine.engineState.clt;
90 }
91 time = getTimeNowMs() - start;
92 if (tempi != 0)
93 efiPrintf("Finished %d iterations of updateSlowSensors in %dms", count, time);
94}
95
96static void testMath(const int count) {
97 time_t start, time;
98
99 int64_t temp64 = 0;
100 start = getTimeNowMs();
101 for (int64_t i = 0; i < count; i++) {
102 temp64 += i;
103 }
104 time = getTimeNowMs() - start;
105 if (temp64 != 0) {
106 efiPrintf("Finished %d iterations of int64_t summation in %dms", count, time);
107 }
108
109 temp64 = 1;
110 start = getTimeNowMs();
111 for (int64_t i = 0; i < count; i++) {
112 temp64 *= i;
113 }
114 time = getTimeNowMs() - start;
115 if (temp64 == 0) {
116 efiPrintf("Finished %d iterations of int64_t multiplication in %dms", count, time);
117 }
118
119 start = getTimeNowMs();
120 for (int i = 0; i < count; i++)
121 ;
122 time = getTimeNowMs() - start;
123 efiPrintf("Finished %d iterations of empty loop in %dms", count, time);
124
125 uint32_t tempi = 1;
126 start = getTimeNowMs();
127 for (int i = 0; i < count; i++) {
128 tempi += tempi;
129 }
130 time = getTimeNowMs() - start;
131 if (tempi == 0) {
132 // 11ms is 1848000 ticks
133 // 18.48 ticks per iteration
134 // Finished 100000 iterations of uint32_t summation in 11ms
135 efiPrintf("Finished %d iterations of uint32_t summation in %dms", count, time);
136 }
137
138 start = getTimeNowMs();
139 tempi = 1;
140 for (int i = 0; i < count; i++) {
141 tempi += (tempi + 100) / 130;
142 }
143 time = getTimeNowMs() - start;
144 if (tempi != 0) {
145 // Finished 100000 iterations of uint32_t division in 16ms
146 efiPrintf("Finished %d iterations of uint32_t division in %dms", count, time);
147 }
148
149 start = getTimeNowMs();
150 temp64 = 1;
151 for (int i = 0; i < count; i++) {
152 temp64 += temp64;
153 }
154 time = getTimeNowMs() - start;
155 if (temp64 == 0) {
156 // Finished 100000 iterations of int64_t summation in 21ms
157 efiPrintf("Finished %d iterations of int64_t summation in %dms", count, time);
158 }
159
160 start = getTimeNowMs();
161 temp64 = 1;
162 for (int i = 0; i < count; i++) {
163 temp64 += (temp64 + 100) / 130;
164 }
165 time = getTimeNowMs() - start;
166 if (temp64 != 0) {
167 // Finished 100000 iterations of int64_t division in 181ms
168 efiPrintf("Finished %d iterations of int64_t division in %dms", count, time);
169 }
170
171 start = getTimeNowMs();
172 float tempf = 1;
173 for (int i = 0; i < count; i++) {
174 tempf += tempf;
175 }
176 time = getTimeNowMs() - start;
177 if (tempf != 0) {
178 efiPrintf("Finished %d iterations of float summation in %dms", count, time);
179 }
180
181 start = getTimeNowMs();
182 tempf = 1;
183 for (int i = 0; i < count; i++) {
184 tempf += tempf * 130.0f;
185 }
186 time = getTimeNowMs() - start;
187 if (tempf != 0) {
188 // ms = ticks
189 // ticks per iteration
190 // Finished 100000 iterations of float division in ms
191 efiPrintf("Finished %d iterations of float multiplication in %dms", count, time);
192 }
193
194 start = getTimeNowMs();
195 tempf = 1;
196 for (int i = 0; i < count; i++) {
197 tempf += (tempf + 100) / 130.0;
198 }
199 time = getTimeNowMs() - start;
200 if (tempf != 0) {
201 // 65 ms = 10920000 ticks
202 // 109.2 ticks per iteration
203 // Finished 100000 iterations of float division in 65ms
204 efiPrintf("Finished %d iterations of float division in %dms", count, time);
205 }
206
207 start = getTimeNowMs();
208 tempf = 1;
209 for (int i = 0; i < count; i++) {
210 tempf += logf(tempf);
211 }
212 time = getTimeNowMs() - start;
213 if (tempf != 0) {
214 // Finished 100000 iterations of float log in 191ms
215 efiPrintf("Finished %d iterations of float log in %dms", count, time);
216 }
217
218 start = getTimeNowMs();
219 double tempd = 1;
220 for (int i = 0; i < count; i++)
221 tempd += tempd / 2;
222 time = getTimeNowMs() - start;
223 if (tempd != 0) {
224 // Finished 100000 iterations of double summation in 80ms
225 efiPrintf("Finished %d iterations of double summation in %dms", count, time);
226 }
227
228 start = getTimeNowMs();
229 tempd = 1;
230 for (int i = 0; i < count; i++)
231 tempd += (tempd + 100) / 130.0;
232 time = getTimeNowMs() - start;
233 if (tempd != 0) {
234 // Finished 100000 iterations of double division in 497ms
235 efiPrintf("Finished %d iterations of double division in %dms", count, time);
236 }
237
238 start = getTimeNowMs();
239 tempd = 1;
240 for (int i = 0; i < count; i++) {
241 tempd += log(tempd);
242 }
243 time = getTimeNowMs() - start;
244 if (tempd != 0) {
245 // Finished 100000 iterations of double log in 242ms
246 efiPrintf("Finished %d iterations of double log in %dms", count, time);
247 }
248}
249
250static void runTests(const int count) {
251 efiPrintf("Running tests: %d", count);
255}
256
257extern Overflow64Counter halTime;
258
259#if EFI_RTC
260static int rtcStartTime;
261#endif
262
263#include "chrtclib.h"
264
265static void timeInfo() {
266 efiPrintf("chTimeNow as seconds = %d", getTimeNowS());
267 efiPrintf("hal seconds = %d", halTime.get() / (long)STM32_SYSCLK);
268
269#if EFI_RTC
270 int unix = rtcGetTimeUnixSec(&RTCD1) - rtcStartTime;
271 efiPrintf("unix seconds = %d", unix);
272#endif
273}
274
275static void runChibioTest() {
276 print("EFI_SHAFT_POSITION_INPUT=%d\r\n", EFI_SHAFT_POSITION_INPUT);
277 print("EFI_EMULATE_POSITION_SENSORS=%d\r\n", EFI_EMULATE_POSITION_SENSORS);
278 print("EFI_ANALOG_SENSORS=%d\r\n", EFI_ANALOG_SENSORS);
279 print("EFI_INTERNAL_ADC=%d\r\n", EFI_INTERNAL_ADC);
280 print("EFI_MAP_AVERAGING=%d\r\n", EFI_MAP_AVERAGING);
281 print("EFI_LOGIC_ANALYZER=%d\r\n", EFI_LOGIC_ANALYZER);
282 print("EFI_ENGINE_SNIFFER=%d\r\n", EFI_ENGINE_SNIFFER);
283 print("EFI_SHAFT_POSITION_INPUT=%d\r\n", EFI_SHAFT_POSITION_INPUT);
284 print("EFI_ENGINE_CONTROL=%d\r\n", EFI_ENGINE_CONTROL);
285 print("CH_DBG_SYSTEM_STATE_CHECK=%d\r\n", CH_DBG_SYSTEM_STATE_CHECK);
286 print("CH_DBG_ENABLE_CHECKS=%d\r\n", CH_DBG_ENABLE_CHECKS);
287 print("CH_DBG_ENABLE_ASSERTS=%d\r\n", CH_DBG_ENABLE_ASSERTS);
288 print("CH_DBG_ENABLE_STACK_CHECK=%d\r\n", CH_DBG_ENABLE_STACK_CHECK);
289 print("CH_DBG_THREADS_PROFILING=%d\r\n", CH_DBG_THREADS_PROFILING);
290 TestThread(getConsoleChannel());
291}
292
294#if EFI_RTC
295 rtcStartTime = rtcGetTimeUnixSec(&RTCD1);
296#endif
297
298 addConsoleActionI("perftest", runTests);
299
300 addConsoleAction("timeinfo", timeInfo);
302}
303
304#endif /* EFI_PERF_METRICS */
void updateSlowSensors()
Definition engine.cpp:208
EngineState engineState
Definition engine.h:344
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
void addConsoleActionI(const char *token, VoidInt callback)
Register a console command with one Integer parameter.
Console package entry point header.
efitimesec_t getTimeNowS()
Current system time in seconds (32 bits)
Definition efitime.cpp:42
efitimems_t getTimeNowMs()
Returns the 32 bit number of milliseconds since the board initialization.
Definition efitime.cpp:34
msg_t TestThread(void *p)
Test execution thread function.
Definition test.c:296
static void testSystemCalls(const int count)
static void testRusefiMethods(const int count)
Overflow64Counter halTime
static void timeInfo()
static int rtcStartTime
static void runTests(const int count)
static void testMath(const int count)
static Engine testEngine
static void runChibioTest()
void initTimePerfActions()
Tests support header.
uint16_t count
Definition tunerstudio.h:1