fork download
  1. // $ gcc -std=c99 -Wall -Wextra -pedantic *.c && time ./a.out
  2. #include <stdint.h> // uintmax_t
  3. #include <stdio.h>
  4. #include <stdlib.h> // system()
  5. #include <time.h>
  6. #include <unistd.h> // sleep()
  7.  
  8. static double double_clock() {
  9. return clock() / (double) CLOCKS_PER_SEC;
  10. }
  11.  
  12. int main(int argc, char* argv[]) {
  13. double start = double_clock();
  14. sleep(1);
  15. printf("after sleep %.2g\n", double_clock() - start);
  16.  
  17. start = double_clock();
  18. system("sleep 1");
  19. printf("after sleep %.2g\n", double_clock() - start);
  20.  
  21. start = double_clock();
  22. int n = (argc == 2) ? atoi(argv[argc-1]) : 500000000;
  23. uintmax_t s = 0;
  24. for (int i = 0; i < n; ++i)
  25. s += i;
  26. if (s != (uintmax_t)(n-1)*(n/2)) return 1;
  27. printf("after loop %.2g\n", double_clock() - start);
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 2.01s 3720KB
stdin
Standard input is empty
stdout
after sleep -2.1e-19
after sleep -2.1e-19
after loop 2