Blob


1 /* See LICENSE file for copyright and license details. */
2 #include <errno.h>
3 #include <math.h>
4 #include <stdint.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
9 #include "../grapheme.h"
10 #include "../gen/word-test.h"
11 #include "util.h"
13 #define NUM_ITERATIONS 10000
15 struct break_benchmark_payload {
16 uint_least32_t *src;
17 size_t srclen;
18 uint_least32_t *dest;
19 size_t destlen;
20 };
22 void
23 libgrapheme(const void *payload)
24 {
25 const struct break_benchmark_payload *p = payload;
27 grapheme_to_uppercase(p->src, p->srclen, p->dest, p->destlen);
28 }
30 int
31 main(int argc, char *argv[])
32 {
33 struct break_benchmark_payload p;
34 double baseline = (double)NAN;
36 (void)argc;
38 if ((p.src = generate_cp_test_buffer(word_break_test,
39 LEN(word_break_test),
40 &(p.srclen))) == NULL) {
41 return 1;
42 }
43 if ((p.dest = calloc((p.destlen = 2 * p.srclen), sizeof(*(p.dest)))) == NULL) {
44 fprintf(stderr, "calloc: Out of memory\n");
45 }
47 printf("%s\n", argv[0]);
48 run_benchmark(libgrapheme, &p, "libgrapheme ", NULL, "codepoint",
49 &baseline, NUM_ITERATIONS, p.srclen - 1);
51 free(p.src);
52 free(p.dest);
54 return 0;
55 }