Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <unistd.h>
- #include <sys/syscall.h>
- static int clock_gettime_syscall(clockid_t clk_id, struct timespec *tp)
- {
- return syscall(__NR_clock_gettime, clk_id, tp);
- }
- int main(void)
- {
- int i;
- struct timespec t, start;
- clock_gettime(CLOCK_REALTIME, &start);
- i = 0;
- do {
- clock_gettime(CLOCK_REALTIME, &t);
- i++;
- } while (t.tv_sec == start.tv_sec || t.tv_nsec < start.tv_nsec);
- printf("vdso hires: %fns\n", 1000000000.0 / i);
- clock_gettime(CLOCK_REALTIME_COARSE, &start);
- i = 0;
- do {
- clock_gettime(CLOCK_REALTIME_COARSE, &t);
- i++;
- } while (t.tv_sec == start.tv_sec || t.tv_nsec < start.tv_nsec);
- printf("vdso coarse: %fns\n", 1000000000.0 / i);
- clock_gettime_syscall(CLOCK_REALTIME, &start);
- i = 0;
- do {
- clock_gettime_syscall(CLOCK_REALTIME, &t);
- i++;
- } while (t.tv_sec == start.tv_sec || t.tv_nsec < start.tv_nsec);
- printf("sysc hires: %fns\n", 1000000000.0 / i);
- clock_gettime_syscall(CLOCK_REALTIME_COARSE, &start);
- i = 0;
- do {
- clock_gettime_syscall(CLOCK_REALTIME_COARSE, &t);
- i++;
- } while (t.tv_sec == start.tv_sec || t.tv_nsec < start.tv_nsec);
- printf("sysc coarse: %fns\n", 1000000000.0 / i);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement