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 *buf;
17 size_t buflen;
18 };
20 void
21 libgrapheme(const void *payload)
22 {
23 const struct break_benchmark_payload *p = payload;
24 size_t off;
26 for (off = 0; off < p->buflen; ) {
27 off += grapheme_next_word_break(p->buf + off, p->buflen - off);
28 }
29 }
31 int
32 main(int argc, char *argv[])
33 {
34 struct break_benchmark_payload p;
35 double baseline = (double)NAN;
37 (void)argc;
39 if ((p.buf = generate_cp_test_buffer(word_break_test,
40 LEN(word_break_test),
41 &(p.buflen))) == NULL) {
42 return 1;
43 }
45 printf("%s\n", argv[0]);
46 run_benchmark(libgrapheme, &p, "libgrapheme ", NULL, "codepoint",
47 &baseline, NUM_ITERATIONS, p.buflen - 1);
49 free(p.buf);
51 return 0;
52 }