Skip to content

Commit e2b3f3c

Browse files
committed
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 <makejian@xiaomi.com>
1 parent 86fe33a commit e2b3f3c

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

benchmarks/whetstone/whetstone.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,11 @@ int main(int argc, FAR char *argv[])
141141
/* added for this version */
142142

143143
long loopstart;
144-
long startsec;
145-
long finisec;
144+
long startmsec;
145+
long finimsec;
146146
float KIPS;
147147
int continuous;
148+
struct timespec ts;
148149

149150
loopstart = 1000; /* see the note about loop below */
150151
continuous = 0;
@@ -173,7 +174,8 @@ int main(int argc, FAR char *argv[])
173174

174175
/* Start benchmark timing at this point. */
175176

176-
startsec = time(0);
177+
clock_gettime(CLOCK_REALTIME, &ts);
178+
startmsec = ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
177179

178180
/* The actual benchmark starts here. */
179181

@@ -429,7 +431,8 @@ int main(int argc, FAR char *argv[])
429431

430432
/* Stop benchmark timing at this point. */
431433

432-
finisec = time(0);
434+
clock_gettime(CLOCK_REALTIME, &ts);
435+
finimsec = ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
433436

434437
/* Performance in Whetstone KIP's per second is given by
435438
*
@@ -439,16 +442,16 @@ int main(int argc, FAR char *argv[])
439442
*/
440443

441444
printf("\n");
442-
if (finisec - startsec <= 0)
445+
if (finimsec - startmsec <= 0)
443446
{
444447
printf("Insufficient duration- Increase the loop count\n");
445448
return 1;
446449
}
447450

448-
printf("Loops: %ld, Iterations: %d, Duration: %ld sec.\n",
449-
loop, ii, finisec - startsec);
451+
printf("Loops: %ld, Iterations: %d, Duration: %ld millisecond.\n",
452+
loop, ii, finimsec - startmsec);
450453

451-
KIPS = (100.0 * loop * ii) / (float)(finisec - startsec);
454+
KIPS = (100.0 * loop * ii) / ((float)(finimsec - startmsec) * 1000);
452455
if (KIPS >= 1000.0)
453456
{
454457
printf("C Converted Double Precision Whetstones: %.1f MIPS\n",

0 commit comments

Comments
 (0)