I. The system call clock_getres(2) and clock_gettime(2) show strange
results.
Consider this small program and its output on OpenBSD 5.0, amd64:
#include <stdio.h>
#include <sys/time.h>
main()
{
struct timespec tp;
int i;
clock_getres(CLOCK_REALTIME, &tp);
printf("Resolution: %lu %lu\n", tp.tv_sec, tp.tv_nsec);
for (i = 0; i < 10; i++) {
clock_gettime(CLOCK_REALTIME, &tp);
printf("Performance: %lu %lu\n", tp.tv_sec, tp.tv_nsec);
}
return 0;
}
Resolution: 0 10000000
Performance: 1331012858 566149475
Performance: 1331012858 566158834
Performance: 1331012858 566164422
Performance: 1331012858 566169031
Performance: 1331012858 566173152
Performance: 1331012858 566177202
Performance: 1331012858 566181253
Performance: 1331012858 566189075
Performance: 1331012858 566195570
Performance: 1331012858 566219945
Surely the clock is resolving better than 10 milliseconds?
II. The man page asserts:
"clock_id can be one of four values: CLOCK_REALTIME for time that
increments as a wall clock should, CLOCK_VIRTUAL for time ..."
How "should" a wall clock increment? Differently from CLOCK_MONOTONIC?
Thank you for your kind attention,
Dave