Branch
Hash :
7b089321
Author :
Date :
2025-01-01T09:24:36
maint: run 'make update-copyright'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
/* Benchmarks for the mbuiterf module.
Copyright (C) 2023-2025 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <uchar.h>
#include "bench.h"
#include "bench-multibyte.h"
#include "mbuiterf.h"
unsigned long long volatile result;
static void
do_test (char test, int repeat, const char *locale_name, const char *text)
{
printf ("Test %c\n", test);
if (setlocale (LC_ALL, locale_name) != NULL)
{
struct timings_state ts;
timing_start (&ts);
int count;
for (count = 0; count < repeat; count++)
{
unsigned long long sum = 0;
mbuif_state_t state;
const char *iter;
for (mbuif_init (state), iter = text; mbuif_avail (state, iter); )
{
mbchar_t cur = mbuif_next (state, iter);
sum += cur.wc;
iter += mb_len (cur);
}
result = sum;
}
timing_end (&ts);
timing_output (&ts);
}
else
{
printf ("Skipping test: locale %s not installed.\n", locale_name);
}
printf ("\n");
}
/* Performs some or all of the following tests:
a - ASCII text, C locale
b - ASCII text, UTF-8 locale
c - French text, C locale
d - French text, ISO-8859-1 locale
e - French text, UTF-8 locale
f - Greek text, C locale
g - Greek text, ISO-8859-7 locale
h - Greek text, UTF-8 locale
i - Chinese text, UTF-8 locale
j - Chinese text, GB18030 locale
Pass the tests to be performed as first argument. */
int
main (int argc, char *argv[])
{
if (argc != 3)
{
fprintf (stderr, "Usage: %s TESTS REPETITIONS\n", argv[0]);
fprintf (stderr, "Example: %s abcdefghij 100000\n", argv[0]);
exit (1);
}
const char *tests = argv[1];
int repeat = atoi (argv[2]);
text_init ();
/* Execute each test. */
size_t i;
for (i = 0; i < strlen (tests); i++)
{
char test = tests[i];
switch (test)
{
case 'a':
do_test (test, repeat, "C", text_latin_ascii);
break;
case 'b':
do_test (test, repeat, "en_US.UTF-8", text_latin_ascii);
break;
case 'c':
do_test (test, repeat, "C", text_french_iso8859);
break;
case 'd':
do_test (test, repeat, "fr_FR.ISO-8859-1", text_french_iso8859);
break;
case 'e':
do_test (test, repeat, "en_US.UTF-8", text_french_utf8);
break;
case 'f':
do_test (test, repeat, "C", text_greek_iso8859);
break;
case 'g':
do_test (test, repeat, "el_GR.ISO-8859-7", text_greek_iso8859);
break;
case 'h':
do_test (test, repeat, "en_US.UTF-8", text_greek_utf8);
break;
case 'i':
do_test (test, repeat, "en_US.UTF-8", text_chinese_utf8);
break;
case 'j':
do_test (test, repeat, "zh_CN.GB18030", text_chinese_gb18030);
break;
default:
/* Ignore. */
;
}
}
return 0;
}