line.c (1057B)
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/line-test.h" 10 #include "../grapheme.h" 11 #include "util.h" 12 13 #define NUM_ITERATIONS 10000 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_line_break(p->buf + off, p->buflen - off); 28 } 29 } 30 31 int 32 main(int argc, char *argv[]) 33 { 34 struct break_benchmark_payload p; 35 double baseline = (double)NAN; 36 37 (void)argc; 38 39 if ((p.buf = generate_cp_test_buffer(line_break_test, 40 LEN(line_break_test), 41 &(p.buflen))) == NULL) { 42 return 1; 43 } 44 45 printf("%s\n", argv[0]); 46 run_benchmark(libgrapheme, &p, "libgrapheme ", NULL, "codepoint", 47 &baseline, NUM_ITERATIONS, p.buflen - 1); 48 49 free(p.buf); 50 51 return 0; 52 }