1 /* Test of times function.
2 Copyright (C) 2008-2020 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Simon Josefsson <simon@josefsson.org>, 2008. */
21 #include <sys/times.h>
23 #include "signature.h"
24 SIGNATURE_CHECK (times
, clock_t, (struct tms
*));
33 doublecmp (const void *p
, const void *q
)
35 double a
= *(double *) p
;
36 double b
= *(double *) q
;
38 return a
< b
? -1 : a
> b
? 1 : 0;
42 main (int argc
, char *argv
[])
47 clock_t clk_tck
= CLK_TCK
;
49 clock_t clk_tck
= sysconf (_SC_CLK_TCK
);
53 if (t
== (clock_t) -1)
61 printf ("clk_tck %ld\n", (long int) clk_tck
);
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
);
72 size_t size
= atoi (argv
[1]);
76 base
= malloc (size
* sizeof (double));
78 for (i
= 0; i
< size
; i
++)
81 qsort (base
, size
, sizeof (double), doublecmp
);
87 if (t
== (clock_t) -1)
95 printf ("clk_tck %ld\n", (long int) clk_tck
);
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
);