termbox2
termbox2 copied to clipboard
Handle all 1-byte codepoints in `tb_iswprint_ex` fast path
Perf boost to avoid binary search on all 1-byte codepoints. Previously it was just for printable ASCII.
I have a implementation that uses a tiny lookup table and bit math and less conditionals. I may update the PR to include that, but I don't expect it to be worth the code complexity.
$ cat test.c
int main(int argc, char **argv) {
int i, n;
uint32_t ch;
uint64_t count;
n = argc >= 2 ? atoi(argv[1]) : 1;
for (i = 0; i < n; i++) {
for (ch = 0; ch <= 0xff; ch++) {
count += tb_wcwidth(ch);
count += tb_iswprint(ch);
}
}
printf("count=%zu\n", count);
return 0;
}
$
$ # compile test-head and test-patch with -O2
$
$ time for i in $(seq 1 10); do ./test-head 100000; done
count=31900000
count=31900000
count=31900000
count=31900000
count=31900000
count=31900000
count=31900000
count=31900000
count=31900000
count=31900000
real 0m3.793s
user 0m3.773s
sys 0m0.020s
$ time for i in $(seq 1 10); do ./test-patch 100000; done
count=31900000
count=31900000
count=31900000
count=31900000
count=31900000
count=31900000
count=31900000
count=31900000
count=31900000
count=31900000
real 0m0.287s
user 0m0.269s
sys 0m0.019s