1 /* Benchmarks for the mbiter 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/>. */
25 #include "bench-multibyte.h"
28 unsigned long long volatile result
;
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
;
39 size_t text_len
= strlen (text
);
41 for (count
= 0; count
< repeat
; count
++)
43 unsigned long long sum
= 0;
45 for (mbi_init (iter
, text
, text_len
); mbi_avail (iter
); mbi_advance (iter
))
47 sum
+= mbi_cur (iter
).wc
;
57 printf ("Skipping test: locale %s not installed.\n", locale_name
);
62 /* Performs some or all of the following tests:
63 a - ASCII text, C locale
64 b - ASCII text, UTF-8 locale
65 c - French text, C locale
66 d - French text, ISO-8859-1 locale
67 e - French text, UTF-8 locale
68 f - Greek text, C locale
69 g - Greek text, ISO-8859-7 locale
70 h - Greek text, UTF-8 locale
71 i - Chinese text, UTF-8 locale
72 j - Chinese text, GB18030 locale
73 Pass the tests to be performed as first argument. */
75 main (int argc
, char *argv
[])
79 fprintf (stderr
, "Usage: %s TESTS REPETITIONS\n", argv
[0]);
80 fprintf (stderr
, "Example: %s abcdefghij 100000\n", argv
[0]);
84 const char *tests
= argv
[1];
85 int repeat
= atoi (argv
[2]);
89 /* Execute each test. */
91 for (i
= 0; i
< strlen (tests
); i
++)
98 do_test (test
, repeat
, "C", text_latin_ascii
);
101 do_test (test
, repeat
, "en_US.UTF-8", text_latin_ascii
);
104 do_test (test
, repeat
, "C", text_french_iso8859
);
107 do_test (test
, repeat
, "fr_FR.ISO-8859-1", text_french_iso8859
);
110 do_test (test
, repeat
, "en_US.UTF-8", text_french_utf8
);
113 do_test (test
, repeat
, "C", text_greek_iso8859
);
116 do_test (test
, repeat
, "el_GR.ISO-8859-7", text_greek_iso8859
);
119 do_test (test
, repeat
, "en_US.UTF-8", text_greek_utf8
);
122 do_test (test
, repeat
, "en_US.UTF-8", text_chinese_utf8
);
125 do_test (test
, repeat
, "zh_CN.GB18030", text_chinese_gb18030
);