mirror of
https://github.com/zoogie/bfCL.git
synced 2025-06-19 11:35:39 -04:00
avoid potentially wrong measurement when clock modified (#16)
This commit is contained in:
parent
f91ce7ae6b
commit
0294bb4de8
12
utils.c
12
utils.c
@ -1,3 +1,7 @@
|
||||
#ifndef _WIN32
|
||||
#define _POSIX_C_SOURCE 199309L
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -79,14 +83,14 @@ long long hp_time_diff(LARGE_INTEGER *pt0, LARGE_INTEGER *pt1) {
|
||||
|
||||
#else
|
||||
|
||||
void get_hp_time(struct timeval *pt) {
|
||||
gettimeofday(pt, NULL);
|
||||
void get_hp_time(struct timespec *pt) {
|
||||
clock_gettime(CLOCK_MONOTONIC, pt);
|
||||
}
|
||||
|
||||
long long hp_time_diff(struct timeval *pt0, struct timeval *pt1) {
|
||||
long long hp_time_diff(struct timespec *pt0, struct timespec *pt1) {
|
||||
long long diff = pt1->tv_sec - pt0->tv_sec;
|
||||
diff *= 1000000;
|
||||
diff += pt1->tv_usec - pt0->tv_usec;
|
||||
diff += (pt1->tv_nsec - pt0->tv_nsec) / 1000;
|
||||
return diff;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user