usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / bench-mbiterf.c
blob7e8128a2a6c2a47379a6cfd8d33b5db659f1a3a0
1 /* Benchmarks for the mbiterf 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 "mbiterf.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 size_t text_len = strlen (text);
40 int count;
41 for (count = 0; count < repeat; count++)
43 unsigned long long sum = 0;
44 const char *text_end = text + text_len;
45 mbif_state_t state;
46 const char *iter;
47 for (mbif_init (state), iter = text; mbif_avail (state, iter, text_end); )
49 mbchar_t cur = mbif_next (state, iter, text_end);
50 sum += cur.wc;
51 iter += mb_len (cur);
53 result = sum;
56 timing_end (&ts);
57 timing_output (&ts);
59 else
61 printf ("Skipping test: locale %s not installed.\n", locale_name);
63 printf ("\n");
66 /* Performs some or all of the following tests:
67 a - ASCII text, C locale
68 b - ASCII text, UTF-8 locale
69 c - French text, C locale
70 d - French text, ISO-8859-1 locale
71 e - French text, UTF-8 locale
72 f - Greek text, C locale
73 g - Greek text, ISO-8859-7 locale
74 h - Greek text, UTF-8 locale
75 i - Chinese text, UTF-8 locale
76 j - Chinese text, GB18030 locale
77 Pass the tests to be performed as first argument. */
78 int
79 main (int argc, char *argv[])
81 if (argc != 3)
83 fprintf (stderr, "Usage: %s TESTS REPETITIONS\n", argv[0]);
84 fprintf (stderr, "Example: %s abcdefghij 100000\n", argv[0]);
85 exit (1);
88 const char *tests = argv[1];
89 int repeat = atoi (argv[2]);
91 text_init ();
93 /* Execute each test. */
94 size_t i;
95 for (i = 0; i < strlen (tests); i++)
97 char test = tests[i];
99 switch (test)
101 case 'a':
102 do_test (test, repeat, "C", text_latin_ascii);
103 break;
104 case 'b':
105 do_test (test, repeat, "en_US.UTF-8", text_latin_ascii);
106 break;
107 case 'c':
108 do_test (test, repeat, "C", text_french_iso8859);
109 break;
110 case 'd':
111 do_test (test, repeat, "fr_FR.ISO-8859-1", text_french_iso8859);
112 break;
113 case 'e':
114 do_test (test, repeat, "en_US.UTF-8", text_french_utf8);
115 break;
116 case 'f':
117 do_test (test, repeat, "C", text_greek_iso8859);
118 break;
119 case 'g':
120 do_test (test, repeat, "el_GR.ISO-8859-7", text_greek_iso8859);
121 break;
122 case 'h':
123 do_test (test, repeat, "en_US.UTF-8", text_greek_utf8);
124 break;
125 case 'i':
126 do_test (test, repeat, "en_US.UTF-8", text_chinese_utf8);
127 break;
128 case 'j':
129 do_test (test, repeat, "zh_CN.GB18030", text_chinese_gb18030);
130 break;
131 default:
132 /* Ignore. */
137 return 0;