bench.c (1322B)
1#include <stdio.h> 2#include <stdlib.h> 3#include <string.h> 4 5#include "utf8proc.h" 6#include "util.h" 7 8int main(int argc, char **argv) 9{ 10 int i, j; 11 int options = 0; 12 13 for (i = 1; i < argc; ++i) { 14 if (!strcmp(argv[i], "-nfkc")) { 15 options |= UTF8PROC_STABLE|UTF8PROC_COMPOSE|UTF8PROC_COMPAT; 16 continue; 17 } 18 if (!strcmp(argv[i], "-nfkd")) { 19 options |= UTF8PROC_STABLE|UTF8PROC_DECOMPOSE|UTF8PROC_COMPAT; 20 continue; 21 } 22 if (!strcmp(argv[i], "-nfc")) { 23 options |= UTF8PROC_STABLE|UTF8PROC_COMPOSE; 24 continue; 25 } 26 if (!strcmp(argv[i], "-nfd")) { 27 options |= UTF8PROC_STABLE|UTF8PROC_DECOMPOSE; 28 continue; 29 } 30 if (!strcmp(argv[i], "-casefold")) { 31 options |= UTF8PROC_CASEFOLD; 32 continue; 33 } 34 if (argv[i][0] == '-') { 35 fprintf(stderr, "unrecognized option: %s\n", argv[i]); 36 return EXIT_FAILURE; 37 } 38 39 size_t len; 40 uint8_t *src = readfile(argv[i], &len); 41 if (!src) { 42 fprintf(stderr, "error reading %s\n", argv[i]); 43 return EXIT_FAILURE; 44 } 45 uint8_t *dest; 46 mytime start = gettime(); 47 for (j = 0; j < 100; ++j) { 48 utf8proc_map(src, len, &dest, options); 49 free(dest); 50 } 51 printf("%s: %g\n", argv[i], elapsed(gettime(), start) / 100); 52 free(src); 53 } 54 55 return EXIT_SUCCESS; 56}