mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-12 05:59:10 +00:00
Make clock_gettime() faster on FreeBSD
This commit is contained in:
parent
5deda43766
commit
5ea618f0af
15 changed files with 67 additions and 18 deletions
|
@ -32,7 +32,9 @@
|
|||
.underrun
|
||||
kClockNames:
|
||||
.e CLOCK_REALTIME,"REALTIME"
|
||||
.e CLOCK_REALTIME_FAST,"REALTIME_FAST"
|
||||
.e CLOCK_MONOTONIC,"MONOTONIC"
|
||||
.e CLOCK_MONOTONIC_FAST,"MONOTONIC_FAST"
|
||||
.e CLOCK_MONOTONIC_RAW,"MONOTONIC_RAW"
|
||||
.e CLOCK_REALTIME_COARSE,"REALTIME_COARSE"
|
||||
.e CLOCK_MONOTONIC_COARSE,"MONOTONIC_COARSE"
|
||||
|
|
|
@ -44,10 +44,10 @@ static long double GetTimeSample(void) {
|
|||
uint64_t tick1, tick2;
|
||||
long double time1, time2;
|
||||
sched_yield();
|
||||
time1 = dtime(CLOCK_REALTIME);
|
||||
time1 = dtime(CLOCK_MONOTONIC_FAST);
|
||||
tick1 = rdtsc();
|
||||
nanosleep(&(struct timespec){0, 1000000}, NULL);
|
||||
time2 = dtime(CLOCK_REALTIME);
|
||||
time2 = dtime(CLOCK_MONOTONIC_FAST);
|
||||
tick2 = rdtsc();
|
||||
return (time2 - time1) * 1e9 / MAX(1, tick2 - tick1);
|
||||
}
|
||||
|
|
|
@ -40,10 +40,10 @@ static long double GetTimeSample(void) {
|
|||
uint64_t tick1, tick2;
|
||||
long double time1, time2;
|
||||
sched_yield();
|
||||
time1 = dtime(CLOCK_REALTIME);
|
||||
time1 = dtime(CLOCK_MONOTONIC);
|
||||
tick1 = rdtsc();
|
||||
nanosleep(&(struct timespec){0, 1000000}, NULL);
|
||||
time2 = dtime(CLOCK_REALTIME);
|
||||
time2 = dtime(CLOCK_MONOTONIC);
|
||||
tick2 = rdtsc();
|
||||
return (time2 - time1) * 1e9 / MAX(1, tick2 - tick1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue