clocktest.c 691 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <signal.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <unistd.h>
  6. #include <stdint.h>
  7. volatile int gotit = 0;
  8. static void
  9. alarm_handler (int signal)
  10. {
  11. gotit = 1;
  12. }
  13. int
  14. main (int argc, char ** argv)
  15. {
  16. clock_t start, stop;
  17. if (signal(SIGALRM, alarm_handler) == SIG_ERR)
  18. {
  19. perror ("signal");
  20. exit (1);
  21. }
  22. alarm(1);
  23. start = clock ();
  24. while (!gotit);
  25. stop = clock ();
  26. printf ("%jd clock ticks per second (start=%jd,stop=%jd)\n",
  27. (intmax_t) (stop - start), (intmax_t) start, (intmax_t) stop);
  28. printf ("CLOCKS_PER_SEC=%jd, sysconf(_SC_CLK_TCK)=%ld\n",
  29. (intmax_t) CLOCKS_PER_SEC, sysconf(_SC_CLK_TCK));
  30. return 0;
  31. }