nstrftime, c-nstrftime tests: Avoid test failures on native Windows.
[gnulib.git] / tests / bench-mbswidth.c
blob0a9f3cf9ae8dc8558808f781c7590efb51e268b6
1 /* Benchmarks for mbswidth().
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 "mbswidth.h"
28 static void
29 do_test (char test, int repeat, const char *locale_name, const char *text)
31 printf ("Test %c\n", test);
32 if (setlocale (LC_ALL, locale_name) != NULL)
34 struct timings_state ts;
35 timing_start (&ts);
37 int count;
38 for (count = 0; count < repeat; count++)
40 mbswidth (text, 0);
43 timing_end (&ts);
44 timing_output (&ts);
46 else
48 printf ("Skipping test: locale %s not installed.\n", locale_name);
50 printf ("\n");
53 /* Performs some or all of the following tests:
54 a - ASCII text, C locale
55 b - ASCII text, UTF-8 locale
56 c - French text, C locale
57 d - French text, ISO-8859-1 locale
58 e - French text, UTF-8 locale
59 f - Greek text, C locale
60 g - Greek text, ISO-8859-7 locale
61 h - Greek text, UTF-8 locale
62 i - Chinese text, UTF-8 locale
63 j - Chinese text, GB18030 locale
64 Pass the tests to be performed as first argument. */
65 int
66 main (int argc, char *argv[])
68 if (argc != 3)
70 fprintf (stderr, "Usage: %s TESTS REPETITIONS\n", argv[0]);
71 fprintf (stderr, "Example: %s abcdefghij 100000\n", argv[0]);
72 exit (1);
75 const char *tests = argv[1];
76 int repeat = atoi (argv[2]);
78 text_init ();
80 /* Execute each test. */
81 size_t i;
82 for (i = 0; i < strlen (tests); i++)
84 char test = tests[i];
86 switch (test)
88 case 'a':
89 do_test (test, repeat, "C", text_latin_ascii);
90 break;
91 case 'b':
92 do_test (test, repeat, "en_US.UTF-8", text_latin_ascii);
93 break;
94 case 'c':
95 do_test (test, repeat, "C", text_french_iso8859);
96 break;
97 case 'd':
98 do_test (test, repeat, "fr_FR.ISO-8859-1", text_french_iso8859);
99 break;
100 case 'e':
101 do_test (test, repeat, "en_US.UTF-8", text_french_utf8);
102 break;
103 case 'f':
104 do_test (test, repeat, "C", text_greek_iso8859);
105 break;
106 case 'g':
107 do_test (test, repeat, "el_GR.ISO-8859-7", text_greek_iso8859);
108 break;
109 case 'h':
110 do_test (test, repeat, "en_US.UTF-8", text_greek_utf8);
111 break;
112 case 'i':
113 do_test (test, repeat, "en_US.UTF-8", text_chinese_utf8);
114 break;
115 case 'j':
116 do_test (test, repeat, "zh_CN.GB18030", text_chinese_gb18030);
117 break;
118 default:
119 /* Ignore. */
124 return 0;