sentence.c (1112B)
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> 8 9 #include "../gen/sentence-test.h" 10 #include "../grapheme.h" 11 #include "util.h" 12 13 #define NUM_ITERATIONS 100000 14 15 struct break_benchmark_payload { 16 uint_least32_t *buf; 17 size_t buflen; 18 }; 19 20 void 21 libgrapheme(const void *payload) 22 { 23 const struct break_benchmark_payload *p = payload; 24 size_t off; 25 26 for (off = 0; off < p->buflen;) { 27 off += grapheme_next_sentence_break(p->buf + off, 28 p->buflen - off); 29 } 30 } 31 32 int 33 main(int argc, char *argv[]) 34 { 35 struct break_benchmark_payload p; 36 double baseline = (double)NAN; 37 38 (void)argc; 39 40 if ((p.buf = generate_cp_test_buffer(sentence_break_test, 41 LEN(sentence_break_test), 42 &(p.buflen))) == NULL) { 43 return 1; 44 } 45 46 printf("%s\n", argv[0]); 47 run_benchmark(libgrapheme, &p, "libgrapheme ", NULL, "codepoint", 48 &baseline, NUM_ITERATIONS, p.buflen - 1); 49 50 free(p.buf); 51 52 return 0; 53 }