uniseg
uniseg copied to clipboard
Graphemes: add fast-path for printable-ASCII
Speedup the handling of strings that contain only printable-ASCII characters by ~20x.
TODO: this commit should probably handle common, but "non-printable" chars like: "\n", "\r".
base: d6773baf
goos: darwin
goarch: arm64
pkg: github.com/rivo/uniseg
name old time/op new time/op delta
GraphemesNext-10 2.73µs ± 0% 2.74µs ± 0% +0.31% (p=0.008 n=5+5)
GraphemesNext_ASCII-10 3.82µs ± 0% 0.19µs ± 1% -95.10% (p=0.008 n=5+5)
name old alloc/op new alloc/op delta
GraphemesNext-10 0.00B 0.00B ~ (all equal)
GraphemesNext_ASCII-10 0.00B 0.00B ~ (all equal)
name old allocs/op new allocs/op delta
GraphemesNext-10 0.00 0.00 ~ (all equal)
GraphemesNext_ASCII-10 0.00 0.00 ~ (all equal)
base: charlievieth/cev/perf
name old time/op new time/op delta
GraphemesNext-10 466ns ± 0% 501ns ± 0% +7.47% (p=0.008 n=5+5)
GraphemesNext_ASCII-10 827ns ± 0% 188ns ± 1% -77.28% (p=0.008 n=5+5)
name old alloc/op new alloc/op delta
GraphemesNext-10 0.00B 0.00B ~ (all equal)
GraphemesNext_ASCII-10 0.00B 0.00B ~ (all equal)
name old allocs/op new allocs/op delta
GraphemesNext-10 0.00 0.00 ~ (all equal)
GraphemesNext_ASCII-10 0.00 0.00 ~ (all equal)
I'm wondering why you would use this package if you only deal with printable ASCII characters.
@charlievieth again, as with my previous comment, if this package uses an internal string
representation it should just ditch the []rune
conversion entirely.
I prefer not to add these kind of exceptions.