File: bench.c

package info (click to toggle)
mame 0.277%2Bdfsg.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 907,524 kB
  • sloc: cpp: 5,198,779; xml: 2,214,830; ansic: 750,334; sh: 34,449; lisp: 19,643; python: 16,298; makefile: 13,238; java: 8,492; yacc: 8,152; javascript: 7,083; cs: 6,013; asm: 4,786; ada: 1,681; pascal: 1,195; lex: 1,174; perl: 585; ruby: 373
file content (56 lines) | stat: -rw-r--r-- 1,322 bytes parent folder | download | duplicates (18)
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;
}