Simplify elapsed time computation

Do as much of the arithmetic in integers as possible.
Convert both parts to final units(msec) and add.
The casts are actually unneeded, but show when the conversions are done.
And drop an unreachable break.
pull/1753/head
George Baltz N3GB 2025-05-14 15:21:24 -04:00
rodzic 29924af2f1
commit 3bdfdebacb
1 zmienionych plików z 2 dodań i 3 usunięć

Wyświetl plik

@ -1959,7 +1959,6 @@ double HAMLIB_API elapsed_ms(struct timespec *start, int option)
//rig_debug(RIG_DEBUG_TRACE, "%s: after gettime, start = %ld,%ld\n", __func__,
// (long)start->tv_sec, (long)start->tv_nsec);
return 999 * 1000; // so we can tell the difference in debug where we came from
break;
case HAMLIB_ELAPSED_INVALIDATE:
clock_gettime(CLOCK_REALTIME, start);
@ -1968,8 +1967,8 @@ double HAMLIB_API elapsed_ms(struct timespec *start, int option)
break;
}
elapsed_msec = ((stop.tv_sec - start->tv_sec) + (stop.tv_nsec / 1e9 -
start->tv_nsec / 1e9)) * 1e3;
elapsed_msec = (double)((stop.tv_sec - start->tv_sec) * 1000) + // sec -> ms
(double)(stop.tv_nsec - start->tv_nsec) / 1e6; // ns -> ms
//rig_debug(RIG_DEBUG_TRACE, "%s: elapsed_msecs=%.0f\n", __func__, elapsed_msec);