Medium
clock_gettime() in a tight loop under strace
Why does strace show almost no clock_gettime syscalls despite the loop calling it millions of times?
main.cpp
#include <time.h>
#include <cstdio>
int main() {
struct timespec ts;
long long sum = 0;
for (int i = 0; i < 10'000'000; ++i) {
clock_gettime(CLOCK_MONOTONIC, &ts);
sum += ts.tv_nsec;
}
printf("%lld\n", sum);
return 0;
}22 of 53 in Operating Systems