This source file includes following definitions.
- doublecmp
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include <sys/times.h>
22
23 #include "signature.h"
24 SIGNATURE_CHECK (times, clock_t, (struct tms *));
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <stdint.h>
29 #include <unistd.h>
30 #include <math.h>
31
32 static int
33 doublecmp (const void *p, const void *q)
34 {
35 double a = *(double *) p;
36 double b = *(double *) q;
37
38 return a < b ? -1 : a > b ? 1 : 0;
39 }
40
41 int
42 main (int argc, char *argv[])
43 {
44 struct tms tms;
45 clock_t t;
46 #ifndef _SC_CLK_TCK
47 clock_t clk_tck = CLK_TCK;
48 #else
49 clock_t clk_tck = sysconf (_SC_CLK_TCK);
50 #endif
51
52 t = times (&tms);
53 if (t == (clock_t) -1)
54 {
55 perror ("times");
56 return EXIT_FAILURE;
57 }
58
59 if (argc > 1)
60 {
61 printf ("clk_tck %ld\n", (long int) clk_tck);
62
63 printf ("t %ld\n", (long int) t);
64 printf ("tms.tms_utime %ldms\n", ((long int) tms.tms_utime * 1000) / (long int) clk_tck);
65 printf ("tms.tms_stime %ldms\n", ((long int) tms.tms_stime * 1000) / (long int) clk_tck);
66 printf ("tms.tms_cutime %ldms\n", ((long int) tms.tms_cutime * 1000) / (long int) clk_tck);
67 printf ("tms.tms_cstime %ldms\n", ((long int) tms.tms_cstime * 1000) / (long int) clk_tck);
68 }
69
70 if (argc > 1)
71 {
72 size_t size = atoi (argv[1]);
73 double *base;
74 size_t i;
75
76 base = malloc (size * sizeof (double));
77
78 for (i = 0; i < size; i++)
79 base[i] = i * i;
80
81 qsort (base, size, sizeof (double), doublecmp);
82
83 free (base);
84 }
85
86 t = times (&tms);
87 if (t == (clock_t) -1)
88 {
89 perror ("times");
90 return EXIT_FAILURE;
91 }
92
93 if (argc > 1)
94 {
95 printf ("clk_tck %ld\n", (long int) clk_tck);
96
97 printf ("t %ld\n", (long int) t);
98 printf ("tms.tms_utime %ldms\n", ((long int) tms.tms_utime * 1000) / (long int) clk_tck);
99 printf ("tms.tms_stime %ldms\n", ((long int) tms.tms_stime * 1000) / (long int) clk_tck);
100 printf ("tms.tms_cutime %ldms\n", ((long int) tms.tms_cutime * 1000) / (long int) clk_tck);
101 printf ("tms.tms_cstime %ldms\n", ((long int) tms.tms_cstime * 1000) / (long int) clk_tck);
102 }
103
104 return 0;
105 }