• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <assert.h>
2 #include <sys/resource.h>
3 
main()4 int main() {
5   struct rusage ru1;
6   struct rusage ru2;
7   long long s1;
8   long long us1;
9   long long s2;
10   long long us2;
11   int r;
12   int success = 0;
13 
14   r = getrusage(RUSAGE_SELF, &ru1);
15   assert(r == 0);
16   s1 = ru1.ru_utime.tv_sec;
17   us1 = ru1.ru_utime.tv_usec;
18 
19   for (int i = 0; i < 10000; i++) {
20     r = getrusage(RUSAGE_SELF, &ru2);
21     assert(r == 0);
22     s2 = ru2.ru_utime.tv_sec;
23     us2 = ru2.ru_utime.tv_usec;
24     assert(s1 <= s2);
25 
26     // Verify that some time has passed.
27     if (s2 > s1 || (s2 == s1 && us2 > us1)) {
28       success = 1;
29       break;
30     }
31   }
32 
33   assert(success == 1);
34 }
35