From 7d37d158e027409072a04efc981d2fd20909fc38 Mon Sep 17 00:00:00 2001 From: mstroh76 Date: Fri, 10 Jan 2025 18:58:09 +0100 Subject: [PATCH] #305 measure single operation time and toggle time --- wiringPi/test/wiringpi_test7_bench.c | 69 ++++++++++++++++------------ 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/wiringPi/test/wiringpi_test7_bench.c b/wiringPi/test/wiringpi_test7_bench.c index 7edc506..d745287 100644 --- a/wiringPi/test/wiringpi_test7_bench.c +++ b/wiringPi/test/wiringpi_test7_bench.c @@ -11,22 +11,24 @@ int ToggleValue = 240000000; -float fExpectMHzdigitalWrite = 10; -float fExpectMHzpinMode = 4; +float fExpectTimedigitalWrite = 1/10; +float fExpectTimedigitalRead = 1/5; +float fExpectTimepinMode = 1/4; +float fWriteReadDelayFactor = 1.77; int GPIO = 19; int GPIOIN = 26; int RaspberryPiModel = -1; -void ReportElaped(const char* msg, const float fExpectMHz, struct timeval t1, struct timeval t2) { +void ReportElapedTime(const char* msg, int multiop, const float fExpectTime, struct timeval t1, struct timeval t2) { double elapsedTime, fTimePerOperation, fFreq; elapsedTime = (t2.tv_sec-t1.tv_sec)+(t2.tv_usec-t1.tv_usec)/1000000.0; - fTimePerOperation = elapsedTime*1000000.0/ToggleValue; - fFreq = ToggleValue/elapsedTime/1000000.0; - printf(" % 9d toggle took %.3f s, Time per toggle %.3f us, Freq %.3f MHz \n", + fTimePerOperation = elapsedTime*1000000.0/ToggleValue/multiop; + fFreq = 1.0f/(fTimePerOperation*2); //ToggleValue/elapsedTime/1000000.0; + printf(" % 9d took %.3f s, Time per operation %.3f us (toggle Freq %.3f MHz) \n", ToggleValue, elapsedTime, fTimePerOperation, fFreq); - CheckSameFloat(msg, fFreq, fExpectMHz, fExpectMHz*0.2f); + CheckSameFloat(msg, fTimePerOperation, fExpectTime, fExpectTime*0.2f); } @@ -53,14 +55,14 @@ int main (void) { case PI_MODEL_AP: case PI_MODEL_CM: ToggleValue /= 7; - fExpectMHzdigitalWrite = 3.8; //MHz; - fExpectMHzpinMode = 1.5; + fExpectTimedigitalWrite = 1/(3.8*2); //MHz; + fExpectTimepinMode = 1/(1.5*2); break; case PI_MODEL_ZERO: case PI_MODEL_ZERO_W: //ARM=1000MHz: 4.8/2.0 ToggleValue /= 5; - fExpectMHzdigitalWrite = 4.8; //MHz; - fExpectMHzpinMode = 2.0; + fExpectTimedigitalWrite = 1/(4.8*2); //MHz; + fExpectTimepinMode = 1/(2.0*2); break; case PI_MODEL_2: ToggleValue /= 4; @@ -78,16 +80,18 @@ int main (void) { case PI_MODEL_CM4: case PI_MODEL_CM4S: ToggleValue = ToggleValue; - fExpectMHzdigitalWrite = 24.5; //MHz; - fExpectMHzpinMode = 4.1; + fExpectTimedigitalWrite = 1/(2*24.5); //MHz; + fExpectTimepinMode = 1/(2*4.1); break; case PI_MODEL_5: ToggleValue = ToggleValue*0.8; - fExpectMHzdigitalWrite = 20.0; //MHz; - fExpectMHzpinMode = 2.5; + fExpectTimedigitalWrite = 1/(2*20.0); //MHz; + fExpectTimepinMode = 1/(2*2.5); break; } + fExpectTimedigitalRead = fExpectTimedigitalWrite*2; + printf("WiringPi GPIO speed test program (using GPIO %d) and toggle %d times\n", GPIO, ToggleValue); @@ -95,40 +99,42 @@ int main (void) { pinMode(GPIO, OUTPUT); - printf("write % 3d million times pin value ...\n", ToggleValue/1000000); + printf("% 3d million times digitalWrite ...\n", ToggleValue/1000000); gettimeofday(&t1, NULL); for (int loop=1; loop Read delay factor", fTimePerOperation/(fExpectTimedigitalWrite+fExpectTimedigitalRead), fWriteReadDelayFactor, 0.2); digitalWrite(GPIO, LOW); pinMode(GPIO, INPUT);