usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / bench-totalorder.c
blobdce0346c32379c451a49227790e12ea441765ccc
1 /* Benchmarks for totalorder*().
2 Copyright (C) 2023-2024 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 #include <config.h>
19 #include <math.h>
20 #include <stdlib.h>
21 #include <string.h>
23 #include "bench.h"
24 #include "infinity.h"
25 #include "macros.h"
26 #include "minus-zero.h"
27 #include "signed-nan.h"
28 #include "signed-snan.h"
30 int volatile tmp;
32 #define FINITE_VALUES \
33 { -1e37 }, \
34 { -1 }, \
35 { -1e-5 }, \
36 { 0 }, \
37 { 1e-5 }, \
38 { 0.5772156649015328606 }, \
39 { 0.6931471805599453094 }, \
40 { 0.8346268416740731863 }, \
41 { 0.91596559417721901505 }, \
42 { 1 }, \
43 { 1.2020569031595942854 }, \
44 { 1.6066951524152917638 }, \
45 { 1.6180339887498948482 }, \
46 { 1.6449340668482264365 }, \
47 { 2.6220575542921198105 }, \
48 { 2.7182818284590452354 }, \
49 { 3.1415926535897932385 }, \
50 { 4.66920160910299067185 }, \
51 { 262537412640768743.99999999999925007 }, \
52 { 1e37 }
54 static void
55 do_float_test (char test, int repeat)
57 printf ("Test %c\n", test);
59 memory_float data[] =
61 #if HAVE_SNANF
62 memory_negative_SNaNf (),
63 memory_positive_SNaNf (),
64 #endif
65 { negative_NaNf () },
66 { positive_NaNf () },
67 { -Infinityf () },
68 { Infinityf () },
69 { minus_zerof },
70 FINITE_VALUES
72 int n = sizeof (data) / sizeof (data[0]);
74 struct timings_state ts;
75 timing_start (&ts);
77 int count;
78 for (count = 0; count < repeat; count++)
80 for (int i = 0; i < n; i++)
81 for (int j = 0; j < n; j++)
82 tmp = totalorderf (&data[i].value, &data[j].value);
85 timing_end (&ts);
86 timing_output (&ts);
87 printf ("\n");
90 static void
91 do_double_test (char test, int repeat)
93 printf ("Test %c\n", test);
95 memory_double data[] =
97 #if HAVE_SNAND
98 memory_negative_SNaNd (),
99 memory_positive_SNaNd (),
100 #endif
101 { negative_NaNd () },
102 { positive_NaNd () },
103 { -Infinityd () },
104 { Infinityd () },
105 { minus_zerod },
106 FINITE_VALUES
108 int n = sizeof (data) / sizeof (data[0]);
110 struct timings_state ts;
111 timing_start (&ts);
113 int count;
114 for (count = 0; count < repeat; count++)
116 for (int i = 0; i < n; i++)
117 for (int j = 0; j < n; j++)
118 tmp = totalorder (&data[i].value, &data[j].value);
121 timing_end (&ts);
122 timing_output (&ts);
123 printf ("\n");
126 static void
127 do_long_double_test (char test, int repeat)
129 printf ("Test %c\n", test);
131 memory_long_double data[] =
133 #if HAVE_SNANL
134 memory_negative_SNaNl (),
135 memory_positive_SNaNl (),
136 #endif
137 { negative_NaNl () },
138 { positive_NaNl () },
139 { -Infinityl () },
140 { Infinityl () },
141 { minus_zerol },
142 FINITE_VALUES
144 int n = sizeof (data) / sizeof (data[0]);
146 struct timings_state ts;
147 timing_start (&ts);
149 int count;
150 for (count = 0; count < repeat; count++)
152 for (int i = 0; i < n; i++)
153 for (int j = 0; j < n; j++)
154 tmp = totalorderl (&data[i].value, &data[j].value);
157 timing_end (&ts);
158 timing_output (&ts);
159 printf ("\n");
162 /* Performs some or all of the following tests:
163 f - float
164 d - double
165 l - long double
166 Pass the tests to be performed as first argument. */
168 main (int argc, char *argv[])
170 if (argc != 3)
172 fprintf (stderr, "Usage: %s TESTS REPETITIONS\n", argv[0]);
173 fprintf (stderr, "Example: %s fdl 1000000\n", argv[0]);
174 exit (1);
177 const char *tests = argv[1];
178 int repeat = atoi (argv[2]);
180 /* Execute each test. */
181 size_t i;
182 for (i = 0; i < strlen (tests); i++)
184 char test = tests[i];
186 switch (test)
188 case 'f':
189 do_float_test (test, repeat);
190 break;
191 case 'd':
192 do_double_test (test, repeat);
193 break;
194 case 'l':
195 do_long_double_test (test, repeat);
196 break;
197 default:
198 /* Ignore. */
203 return 0;