1
0
mirror of https://github.com/golang/go synced 2024-11-13 20:10:32 -07:00
go/src/unicode
Ilya Tocar bc8bb5b27a unicode: speed-up is16/is32
Avoid division in common case. There are 5438 ranges in unicode/tables.go
4110 of them have stride 1.
Stride 1 case got significantly faster. Other stride is a bit slower.
Measured by

import (
	"testing"
	"unicode"
)

func BenchmarkDiv1(b *testing.B) {
	rtb := &unicode.RangeTable{
		R16: []unicode.Range16{
			{0xa800, 0xdfff, 1}, // or 3
		},
	}
	for i := 0; i < b.N; i++ {
		unicode.Is(rtb, rune(0xc700))
	}
}

Div1-6  15.6ns ± 1%   9.9ns ± 1%  -36.54%  (p=0.000 n=10+10)
Div3-6  15.5ns ± 1%  16.1ns ± 1%   +3.67%  (p=0.000 n=10+10)

Helps a bit with xml parsing from issue #21823

XMLsax-6   30.9s ± 0%   29.6s ± 0%  -4.15%  (p=0.000 n=10+9)

Change-Id: Ibac1a91d7b9474d0c134b0add83e56caa62daa20
Reviewed-on: https://go-review.googlesource.com/63390
Run-TryBot: Ilya Tocar <ilya.tocar@intel.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-09-12 21:32:50 +00:00
..
utf8 unicode/utf8: make FullRune inlinable 2017-09-12 20:18:53 +00:00
utf16
casetables.go
digit_test.go
digit.go
example_test.go
graphic_test.go
graphic.go
letter_test.go
letter.go unicode: speed-up is16/is32 2017-09-12 21:32:50 +00:00
maketables.go unicode: move scripts from FoldCategories to FoldScripts 2017-06-15 01:05:31 +00:00
script_test.go
tables.go unicode: move scripts from FoldCategories to FoldScripts 2017-06-15 01:05:31 +00:00