This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit 22f85e8b61de4fe8b22fd6224601363f28901a68
Author: makejian <[email protected]>
AuthorDate: Thu May 29 20:50:13 2025 +0800

    benchmarks/fpu: improve timing precision to milliseconds
    
    Change FPU benchmark timing from seconds to milliseconds for better 
accuracy.
    This allows for more precise measurement of test cycles, especially for
    shorter test runs that previously completed within a single second.
    
    Signed-off-by: makejian <[email protected]>
---
 benchmarks/whetstone/whetstone.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/benchmarks/whetstone/whetstone.c b/benchmarks/whetstone/whetstone.c
index 4363baaf7..dbc8247fd 100644
--- a/benchmarks/whetstone/whetstone.c
+++ b/benchmarks/whetstone/whetstone.c
@@ -143,10 +143,11 @@ int main(int argc, FAR char *argv[])
   /* added for this version */
 
   long loopstart;
-  long startsec;
-  long finisec;
+  long startmsec;
+  long finimsec;
   float KIPS;
   int continuous;
+  struct timespec ts;
 
   loopstart = 1000;    /* see the note about loop below */
   continuous = 0;
@@ -175,7 +176,8 @@ LCONT:
 
   /* Start benchmark timing at this point. */
 
-  startsec = time(0);
+  clock_gettime(CLOCK_REALTIME, &ts);
+  startmsec = ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
 
   /* The actual benchmark starts here. */
 
@@ -431,7 +433,8 @@ IILOOP:
 
   /* Stop benchmark timing at this point. */
 
-  finisec = time(0);
+  clock_gettime(CLOCK_REALTIME, &ts);
+  finimsec = ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
 
   /* Performance in Whetstone KIP's per second is given by
    *
@@ -441,16 +444,16 @@ IILOOP:
    */
 
   printf("\n");
-  if (finisec - startsec <= 0)
+  if (finimsec - startmsec <= 0)
     {
       printf("Insufficient duration- Increase the loop count\n");
       return 1;
     }
 
-  printf("Loops: %ld, Iterations: %d, Duration: %ld sec.\n",
-                                loop, ii, finisec - startsec);
+  printf("Loops: %ld, Iterations: %d, Duration: %ld millisecond.\n",
+                                loop, ii, finimsec - startmsec);
 
-  KIPS = (100.0 * loop * ii) / (float)(finisec - startsec);
+  KIPS = (100.0 * loop * ii) / ((float)(finimsec - startmsec) * 1000);
   if (KIPS >= 1000.0)
     {
       printf("C Converted Double Precision Whetstones: %.1f MIPS\n",

Reply via email to