rivo / uniseg

Unicode Text Segmentation, Word Wrapping, and String Width Calculation in Go
MIT License
585 stars 62 forks source link

Faster split as runes, reduced memory usage, allocs #8

Closed dolmen closed 3 years ago

dolmen commented 4 years ago

This is an alternative to #5 (Cc: @Code-Hex). A bit slower than #5, but much less memory used. Still significantly faster than the original NewGraphemes.

The second commit is the benchmark. Just cherry-pick the first commit if you don't want the benchmark.

$ go test -benchmem -bench B
goos: darwin
goarch: amd64
pkg: github.com/rivo/uniseg
BenchmarkCountOriginal-4        2991        387297 ns/op       96392 B/op       3458 allocs/op
BenchmarkCountCodeHex-4         4665        274718 ns/op      105544 B/op       1865 allocs/op
BenchmarkCountDolmen-4          4227        291797 ns/op       77776 B/op       1865 allocs/op
dolmen commented 3 years ago

@rivo ping

rivo commented 3 years ago

Sorry. Too many things going on at the same time. I merged the change (not the benchmark, though, for now).