#counting #length #chars #count #faster

no-std faster-chars-count

Library for counting length of chars faster than Chars::count()

6 releases

0.3.0 Nov 18, 2021
0.2.1 May 18, 2021
0.1.7 Apr 29, 2021
0.1.5 Mar 5, 2021

#1021 in Text processing

Download history 19/week @ 2024-02-19 5/week @ 2024-02-26 104/week @ 2024-04-01

104 downloads per month

MIT license

9KB
124 lines

Library for counting length of chars faster than Chars::count()

Idea is from UTF-8のコードポイントはどうやって高速に数えるか, and UTF-8のコードポイントはどうやってもっと高速に数えるか.

usage

//before
"Hello, world!".chars().count();

//after
"Hello, world!".chars_count();

bench

repeated "a" (only 1byte utf8)

Length std chars_count chars_count(avx2)
1 1.3906 ns 3.1607 ns 2.1750 ns
10 4.7844 ns 5.6093 ns 7.2465 ns
100 47.630 ns 10.607 ns 11.265 ns
1000 475.17 ns 67.364 ns 17.839 ns
10000 4.7231 us 604.66 ns 91.757 ns

bench 1byte

repeated "錆" (only 3byte utf8)

Length std chars_count chars_count(avx2)
1 2.4324 ns 4.5069 ns 4.2662 ns
10 13.947 ns 10.267 ns 11.984 ns
100 143.74 ns 23.935 ns 28.758 ns
1000 1.4210 us 193.98 ns 40.435 ns
10000 1.8505 us 270.60 ns 14.206 us

bench 3byte

See performance branch for details.

future plan

sse (128bit)

avx512 UTF-8のコードポイントはどうやってAVX-512で高速に数えるか

No runtime deps

Features