Skip to content

Commit 2d8cb9f

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 05ebb8a commit 2d8cb9f

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
@@ -143,10 +143,11 @@ int main(int argc, FAR char *argv[])
143143
/* added for this version */
144144

145145
long loopstart;
146-
long startsec;
147-
long finisec;
146+
long startmsec;
147+
long finimsec;
148148
float KIPS;
149149
int continuous;
150+
struct timespec ts;
150151

151152
loopstart = 1000; /* see the note about loop below */
152153
continuous = 0;
@@ -175,7 +176,8 @@ int main(int argc, FAR char *argv[])
175176

176177
/* Start benchmark timing at this point. */
177178

178-
startsec = time(0);
179+
clock_gettime(CLOCK_REALTIME, &ts);
180+
startmsec = ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
179181

180182
/* The actual benchmark starts here. */
181183

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

432434
/* Stop benchmark timing at this point. */
433435

434-
finisec = time(0);
436+
clock_gettime(CLOCK_REALTIME, &ts);
437+
finimsec = ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
435438

436439
/* Performance in Whetstone KIP's per second is given by
437440
*
@@ -441,16 +444,16 @@ int main(int argc, FAR char *argv[])
441444
*/
442445

443446
printf("\n");
444-
if (finisec - startsec <= 0)
447+
if (finimsec - startmsec <= 0)
445448
{
446449
printf("Insufficient duration- Increase the loop count\n");
447450
return 1;
448451
}
449452

450-
printf("Loops: %ld, Iterations: %d, Duration: %ld sec.\n",
451-
loop, ii, finisec - startsec);
453+
printf("Loops: %ld, Iterations: %d, Duration: %ld millisecond.\n",
454+
loop, ii, finimsec - startmsec);
452455

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

0 commit comments

Comments
 (0)