Mercurial > minori
comparison dep/utf8proc/bench/unistring.c @ 343:1faa72660932
*: transfer back to cmake from autotools
autotools just made lots of things more complicated than
they should have and many things broke (i.e. translations)
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Thu, 20 Jun 2024 05:56:06 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
342:adb79bdde329 | 343:1faa72660932 |
---|---|
1 /* comparative benchmark of GNU libunistring */ | |
2 | |
3 #include <stdio.h> | |
4 #include <stdlib.h> | |
5 #include <string.h> | |
6 | |
7 /* libunistring */ | |
8 #include <unistr.h> | |
9 #include <uninorm.h> | |
10 | |
11 #include "util.h" | |
12 | |
13 int main(int argc, char **argv) | |
14 { | |
15 int i; | |
16 uninorm_t nf = UNINORM_NFKC; | |
17 | |
18 for (i = 1; i < argc; ++i) { | |
19 if (!strcmp(argv[i], "-nfkc")) { | |
20 nf = UNINORM_NFKC; | |
21 continue; | |
22 } | |
23 if (!strcmp(argv[i], "-nfkd")) { | |
24 nf = UNINORM_NFKD; | |
25 continue; | |
26 } | |
27 if (!strcmp(argv[i], "-nfc")) { | |
28 nf = UNINORM_NFC; | |
29 continue; | |
30 } | |
31 if (!strcmp(argv[i], "-nfd")) { | |
32 nf = UNINORM_NFD; | |
33 continue; | |
34 } | |
35 if (argv[i][0] == '-') { | |
36 fprintf(stderr, "unrecognized option: %s\n", argv[i]); | |
37 return EXIT_FAILURE; | |
38 } | |
39 | |
40 size_t len; | |
41 uint8_t *src = readfile(argv[i], &len); | |
42 if (!src) { | |
43 fprintf(stderr, "error reading %s\n", argv[i]); | |
44 return EXIT_FAILURE; | |
45 } | |
46 | |
47 size_t destlen; | |
48 uint8_t *dest; | |
49 mytime start = gettime(); | |
50 for (int i = 0; i < 100; ++i) { | |
51 dest = u8_normalize(nf, src, len, NULL, &destlen); | |
52 if (!dest) return EXIT_FAILURE; | |
53 free(dest); | |
54 } | |
55 printf("%s: %g\n", argv[i], elapsed(gettime(), start) / 100); | |
56 free(src); | |
57 } | |
58 | |
59 return EXIT_SUCCESS; | |
60 } |