usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / bench-mbuiterf.c
blob3992c6c8874b7561cb1165fdcd701fb341d410f0
1 /* Benchmarks for the mbuiterf module.
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 <stdlib.h>
20 #include <string.h>
21 #include <locale.h>
22 #include <uchar.h>
24 #include "bench.h"
25 #include "bench-multibyte.h"
26 #include "mbuiterf.h"
28 unsigned long long volatile result;
30 static void
31 do_test (char test, int repeat, const char *locale_name, const char *text)
33 printf ("Test %c\n", test);
34 if (setlocale (LC_ALL, locale_name) != NULL)
36 struct timings_state ts;
37 timing_start (&ts);
39 int count;
40 for (count = 0; count < repeat; count++)
42 unsigned long long sum = 0;
43 mbuif_state_t state;
44 const char *iter;
45 for (mbuif_init (state), iter = text; mbuif_avail (state, iter); )
47 mbchar_t cur = mbuif_next (state, iter);
48 sum += cur.wc;
49 iter += mb_len (cur);
51 result = sum;
54 timing_end (&ts);
55 timing_output (&ts);
57 else
59 printf ("Skipping test: locale %s not installed.\n", locale_name);
61 printf ("\n");
64 /* Performs some or all of the following tests:
65 a - ASCII text, C locale
66 b - ASCII text, UTF-8 locale
67 c - French text, C locale
68 d - French text, ISO-8859-1 locale
69 e - French text, UTF-8 locale
70 f - Greek text, C locale
71 g - Greek text, ISO-8859-7 locale
72 h - Greek text, UTF-8 locale
73 i - Chinese text, UTF-8 locale
74 j - Chinese text, GB18030 locale
75 Pass the tests to be performed as first argument. */
76 int
77 main (int argc, char *argv[])
79 if (argc != 3)
81 fprintf (stderr, "Usage: %s TESTS REPETITIONS\n", argv[0]);
82 fprintf (stderr, "Example: %s abcdefghij 100000\n", argv[0]);
83 exit (1);
86 const char *tests = argv[1];
87 int repeat = atoi (argv[2]);
89 text_init ();
91 /* Execute each test. */
92 size_t i;
93 for (i = 0; i < strlen (tests); i++)
95 char test = tests[i];
97 switch (test)
99 case 'a':
100 do_test (test, repeat, "C", text_latin_ascii);
101 break;
102 case 'b':
103 do_test (test, repeat, "en_US.UTF-8", text_latin_ascii);
104 break;
105 case 'c':
106 do_test (test, repeat, "C", text_french_iso8859);
107 break;
108 case 'd':
109 do_test (test, repeat, "fr_FR.ISO-8859-1", text_french_iso8859);
110 break;
111 case 'e':
112 do_test (test, repeat, "en_US.UTF-8", text_french_utf8);
113 break;
114 case 'f':
115 do_test (test, repeat, "C", text_greek_iso8859);
116 break;
117 case 'g':
118 do_test (test, repeat, "el_GR.ISO-8859-7", text_greek_iso8859);
119 break;
120 case 'h':
121 do_test (test, repeat, "en_US.UTF-8", text_greek_utf8);
122 break;
123 case 'i':
124 do_test (test, repeat, "en_US.UTF-8", text_chinese_utf8);
125 break;
126 case 'j':
127 do_test (test, repeat, "zh_CN.GB18030", text_chinese_gb18030);
128 break;
129 default:
130 /* Ignore. */
135 return 0;