1 /* See LICENSE file for copyright and license details. */
9 #include "../grapheme.h"
10 #include "../gen/character-test.h"
15 #define NUM_ITERATIONS 100000
17 struct break_benchmark_payload {
19 utf8proc_int32_t *buf_utf8proc;
24 libgrapheme(const void *payload)
26 uint_least16_t state = 0;
27 const struct break_benchmark_payload *p = payload;
30 for (i = 0; i + 1 < p->buflen; i++) {
31 (void)grapheme_is_character_break(p->buf[i], p->buf[i+1],
37 libutf8proc(const void *payload)
39 utf8proc_int32_t state = 0;
40 const struct break_benchmark_payload *p = payload;
43 for (i = 0; i + 1 < p->buflen; i++) {
44 (void)utf8proc_grapheme_break_stateful(p->buf_utf8proc[i],
51 main(int argc, char *argv[])
53 struct break_benchmark_payload p;
54 double baseline = (double)NAN;
59 if ((p.buf = generate_cp_test_buffer(character_break_test,
60 LEN(character_break_test),
61 &(p.buflen))) == NULL) {
64 if ((p.buf_utf8proc = malloc(p.buflen * sizeof(*(p.buf_utf8proc)))) == NULL) {
65 fprintf(stderr, "malloc: %s\n", strerror(errno));
68 for (i = 0; i < p.buflen; i++) {
70 * there is no overflow, as we know that the maximum
71 * codepoint is 0x10FFFF, which is way below 2^31
73 p.buf_utf8proc[i] = (utf8proc_int32_t)p.buf[i];
76 printf("%s\n", argv[0]);
77 run_benchmark(libgrapheme, &p, "libgrapheme ", NULL, "comparison",
78 &baseline, NUM_ITERATIONS, p.buflen - 1);
79 run_benchmark(libutf8proc, &p, "libutf8proc ", NULL, "comparison",
80 &baseline, NUM_ITERATIONS, p.buflen - 1);