1 /* Benchmarks for totalorder*().
2 Copyright (C) 2023-2025 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/>. */
26 #include "minus-zero.h"
27 #include "signed-nan.h"
28 #include "signed-snan.h"
32 #define FINITE_VALUES \
38 { 0.5772156649015328606 }, \
39 { 0.6931471805599453094 }, \
40 { 0.8346268416740731863 }, \
41 { 0.91596559417721901505 }, \
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 }, \
55 do_float_test (char test
, int repeat
)
57 printf ("Test %c\n", test
);
62 memory_negative_SNaNf (),
63 memory_positive_SNaNf (),
72 int n
= sizeof (data
) / sizeof (data
[0]);
74 struct timings_state ts
;
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
);
91 do_double_test (char test
, int repeat
)
93 printf ("Test %c\n", test
);
95 memory_double data
[] =
98 memory_negative_SNaNd (),
99 memory_positive_SNaNd (),
101 { negative_NaNd () },
102 { positive_NaNd () },
108 int n
= sizeof (data
) / sizeof (data
[0]);
110 struct timings_state ts
;
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
);
127 do_long_double_test (char test
, int repeat
)
129 printf ("Test %c\n", test
);
131 memory_long_double data
[] =
134 memory_negative_SNaNl (),
135 memory_positive_SNaNl (),
137 { negative_NaNl () },
138 { positive_NaNl () },
144 int n
= sizeof (data
) / sizeof (data
[0]);
146 struct timings_state ts
;
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
);
162 /* Performs some or all of the following tests:
166 Pass the tests to be performed as first argument. */
168 main (int argc
, char *argv
[])
172 fprintf (stderr
, "Usage: %s TESTS REPETITIONS\n", argv
[0]);
173 fprintf (stderr
, "Example: %s fdl 1000000\n", argv
[0]);
177 const char *tests
= argv
[1];
178 int repeat
= atoi (argv
[2]);
180 /* Execute each test. */
182 for (i
= 0; i
< strlen (tests
); i
++)
184 char test
= tests
[i
];
189 do_float_test (test
, repeat
);
192 do_double_test (test
, repeat
);
195 do_long_double_test (test
, repeat
);