mattn / go-runewidth

wcwidth for golang
MIT License
609 stars 94 forks source link

Runewidth speedup #47

Closed markus-oberhumer closed 3 years ago

markus-oberhumer commented 3 years ago

This results in a 6x speedup for the common case RuneWidth768.

name                        old time/op  new time/op  delta
RuneWidth768-4              21.5µs ± 0%   2.7µs ± 0%  -87.27%  (p=0.029 n=4+4)
RuneWidthAll-4              51.1ms ± 0%  45.3ms ± 0%  -11.38%  (p=0.029 n=4+4)
String1Width768-4            219µs ± 2%   198µs ± 2%   -9.73%  (p=0.029 n=4+4)
RuneWidth768EastAsian-4     35.6µs ± 0%  34.2µs ± 0%   -3.86%  (p=0.029 n=4+4)
RuneWidthAllEastAsian-4     71.5ms ± 0%  69.1ms ± 0%   -3.26%  (p=0.029 n=4+4)
String1WidthAll-4            356ms ± 1%   353ms ± 2%     ~     (p=0.343 n=4+4)
String1WidthAllEastAsian-4   378ms ± 1%   378ms ± 2%     ~     (p=0.886 n=4+4)
String1Width768EastAsian-4   236µs ± 1%   235µs ± 2%     ~     (p=0.886 n=4+4)
[Geo mean]                  3.44ms       2.56ms       -25.63%
makew0rld commented 3 years ago

How does this compare with #42?

markus-oberhumer commented 3 years ago

How does this compare with #42?

Should be about the same. Once this request is merged more micro-optimizations can easily be made because of the new benchmarks.

mattn commented 3 years ago

Could you please resolve conflicts?

markus-oberhumer commented 3 years ago

Will do, but please fix the master branch first - commit c9bd7d1b27861f3068ba9182eb78d14a3282bdd8 seems broken.

mattn commented 3 years ago

I merged this.

https://github.com/mattn/go-runewidth/commit/43a826dcfbd153f169a11fce22952a327a265edc