mirror of
https://github.com/prirun/p50em.git
synced 2026-01-11 23:42:56 +00:00
The cmraw tool shows the approximate minimum time a program could nanosleep, which tends to be quite a bit bigger than the smallest value one could pass to nanosleep (one ns). For example, on my i7-3770 running linux, the results tend to be between 90 and 120 ns.
36 lines
837 B
C
36 lines
837 B
C
/* Show approximate minimum clock resolution
|
|
Derived from the example in the linux man page for clock_gettime() */
|
|
|
|
#define _XOPEN_SOURCE 600
|
|
#include <time.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdbool.h>
|
|
#include <unistd.h>
|
|
|
|
static void displayClock(clockid_t clock, char *name)
|
|
{
|
|
struct timespec ts;
|
|
time_t oldsec;
|
|
long oldnsec;
|
|
|
|
clock_gettime(clock, &ts);
|
|
oldsec = ts.tv_sec;
|
|
oldnsec = ts.tv_nsec;
|
|
while (ts.tv_sec == oldsec && ts.tv_nsec == oldnsec)
|
|
{
|
|
if (clock_gettime(clock, &ts) == -1) {
|
|
perror("clock_gettime");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
printf("%-15s: %10ld sec %09ld nsec\n", name,
|
|
(long) ts.tv_sec - oldsec, ts.tv_nsec - oldnsec);
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
displayClock(CLOCK_MONOTONIC_RAW, "CLOCK_MONOTONIC_RAW");
|
|
exit(0);
|
|
}
|