summaryrefslogtreecommitdiffstats
path: root/src/utf8proc/bench/bench.c
blob: 4932c6d44b0466654e14e56430c83ed61381f757 (plain)
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "utf8proc.h"
#include "util.h"

int main(int argc, char **argv)
{
	 int i, j;
	 int options = 0;
	 
	 for (i = 1; i < argc; ++i) {
		  if (!strcmp(argv[i], "-nfkc")) {
			   options |= UTF8PROC_STABLE|UTF8PROC_COMPOSE|UTF8PROC_COMPAT;
			   continue;
		  }
		  if (!strcmp(argv[i], "-nfkd")) {
			   options |= UTF8PROC_STABLE|UTF8PROC_DECOMPOSE|UTF8PROC_COMPAT;
			   continue;
		  }
		  if (!strcmp(argv[i], "-nfc")) {
			   options |= UTF8PROC_STABLE|UTF8PROC_COMPOSE;
			   continue;
		  }
		  if (!strcmp(argv[i], "-nfd")) {
			   options |= UTF8PROC_STABLE|UTF8PROC_DECOMPOSE;
			   continue;
		  }
		  if (!strcmp(argv[i], "-casefold")) {
			   options |= UTF8PROC_CASEFOLD;
			   continue;
		  }
		  if (argv[i][0] == '-') {
			   fprintf(stderr, "unrecognized option: %s\n", argv[i]);
			   return EXIT_FAILURE;
		  }

		  size_t len;
		  uint8_t *src = readfile(argv[i], &len);
		  if (!src) {
			   fprintf(stderr, "error reading %s\n", argv[i]);
			   return EXIT_FAILURE;
		  }
		  uint8_t *dest;
		  mytime start = gettime();
		  for (j = 0; j < 100; ++j) {
			   utf8proc_map(src, len, &dest, options);
			   free(dest);
		  }
		  printf("%s: %g\n", argv[i], elapsed(gettime(), start) / 100);
		  free(src);
	 }

	 return EXIT_SUCCESS;
}