summaryrefslogtreecommitdiff
path: root/time/clocktest.c
diff options
context:
space:
mode:
Diffstat (limited to 'time/clocktest.c')
-rw-r--r--time/clocktest.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/time/clocktest.c b/time/clocktest.c
index 0a248aa181..570c194a81 100644
--- a/time/clocktest.c
+++ b/time/clocktest.c
@@ -1,16 +1,31 @@
+#include <signal.h>
#include <stdio.h>
#include <time.h>
+#include <unistd.h>
-main ()
+volatile int gotit = 0;
+
+void
+alarm_handler (int signal)
+{
+ gotit = 1;
+}
+
+
+int
+main (int argc, char ** argv)
{
- volatile int i;
- double t1, t2, t;
+ clock_t start, stop;
- t1 = (double) clock ();
- for (i = 0; i < 100000; ++i) ;
- t2 = (double) clock ();
+ signal(SIGALRM, alarm_handler);
+ alarm(1);
+ start = clock ();
+ while (!gotit);
+ stop = clock ();
- t = (t2 - t1) / ((double) CLOCKS_PER_SEC);
- printf ("%f - %f = %f\n",t2,t1,t);
+ printf ("%ld clock ticks per second (start=%ld,stop=%ld)\n",
+ stop - start, start, stop);
+ printf ("CLOCKS_PER_SEC=%d, sysconf(_SC_CLK_TCK)=%ld\n",
+ CLOCKS_PER_SEC, sysconf(_SC_CLK_TCK));
return 0;
}