mirror of https://github.com/gobwas/glob.git
tune
This commit is contained in:
parent
57a5246fac
commit
61a66d485f
|
@ -168,6 +168,15 @@ func BenchmarkAllGlobMatch(b *testing.B) {
|
||||||
_ = m.Match(fixture_all_match)
|
_ = m.Match(fixture_all_match)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func BenchmarkAllGlobMatchParallel(b *testing.B) {
|
||||||
|
m, _ := Compile(pattern_all)
|
||||||
|
|
||||||
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
|
for pb.Next() {
|
||||||
|
_ = m.Match(fixture_all_match)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
func BenchmarkAllRegexpMatch(b *testing.B) {
|
func BenchmarkAllRegexpMatch(b *testing.B) {
|
||||||
m := regexp.MustCompile(regexp_all)
|
m := regexp.MustCompile(regexp_all)
|
||||||
f := []byte(fixture_all_match)
|
f := []byte(fixture_all_match)
|
||||||
|
|
|
@ -42,8 +42,15 @@ func toPowerOfTwo(v int) int {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
minSegment = 32
|
||||||
|
minSegmentMinusOne = 31
|
||||||
|
maxSegment = 1024
|
||||||
|
maxSegmentMinusOne = 1023
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
for i := 1024; i >= 1; i >>= 1 {
|
for i := maxSegment; i >= minSegment; i >>= 1 {
|
||||||
func(i int) {
|
func(i int) {
|
||||||
segmentsPools[i-1] = sync.Pool{
|
segmentsPools[i-1] = sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() interface{} {
|
||||||
|
@ -54,41 +61,29 @@ func init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var segmentsPool = sync.Pool{
|
|
||||||
New: func() interface{} {
|
|
||||||
return make([]int, 0, 64)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func getIdx(c int) int {
|
func getIdx(c int) int {
|
||||||
p := toPowerOfTwo(c)
|
p := toPowerOfTwo(c)
|
||||||
switch {
|
switch {
|
||||||
case p >= 1024:
|
case p >= maxSegment:
|
||||||
return 1023
|
return maxSegmentMinusOne
|
||||||
case p < 1:
|
case p <= minSegment:
|
||||||
return 0
|
return minSegmentMinusOne
|
||||||
default:
|
default:
|
||||||
return p - 1
|
return p - 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func acquireSegments(c int) []int {
|
func acquireSegments(c int) []int {
|
||||||
|
// fmt.Println("GET", getIdx(c))
|
||||||
return segmentsPools[getIdx(c)].Get().([]int)[:0]
|
return segmentsPools[getIdx(c)].Get().([]int)[:0]
|
||||||
}
|
}
|
||||||
|
|
||||||
func releaseSegments(s []int) {
|
func releaseSegments(s []int) {
|
||||||
|
// fmt.Println("PUT", getIdx(cap(s)))
|
||||||
segmentsPools[getIdx(cap(s))].Put(s)
|
segmentsPools[getIdx(cap(s))].Put(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendIfNotAsPrevious(target []int, val int) []int {
|
// appendMerge merges and sorts given already SORTED and UNIQUE segments.
|
||||||
l := len(target)
|
|
||||||
if l != 0 && target[l-1] == val {
|
|
||||||
return target
|
|
||||||
}
|
|
||||||
|
|
||||||
return append(target, val)
|
|
||||||
}
|
|
||||||
|
|
||||||
func appendMerge(target, sub []int) []int {
|
func appendMerge(target, sub []int) []int {
|
||||||
lt, ls := len(target), len(sub)
|
lt, ls := len(target), len(sub)
|
||||||
out := acquireSegments(lt + ls)
|
out := acquireSegments(lt + ls)
|
||||||
|
@ -131,64 +126,6 @@ func appendMerge(target, sub []int) []int {
|
||||||
return target
|
return target
|
||||||
}
|
}
|
||||||
|
|
||||||
// mergeSegments merges and sorts given already SORTED and UNIQUE segments.
|
|
||||||
func mergeSegments(list [][]int, out []int) []int {
|
|
||||||
var current []int
|
|
||||||
switch len(list) {
|
|
||||||
case 0:
|
|
||||||
return out
|
|
||||||
case 1:
|
|
||||||
return list[0]
|
|
||||||
default:
|
|
||||||
current = acquireSegments(len(list[0]))
|
|
||||||
current = append(current, list[0]...)
|
|
||||||
// releaseSegments(list[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, s := range list[1:] {
|
|
||||||
next := acquireSegments(len(current) + len(s))
|
|
||||||
for x, y := 0, 0; x < len(current) || y < len(s); {
|
|
||||||
if x >= len(current) {
|
|
||||||
next = append(next, s[y:]...)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if y >= len(s) {
|
|
||||||
next = append(next, current[x:]...)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
xValue := current[x]
|
|
||||||
yValue := s[y]
|
|
||||||
|
|
||||||
switch {
|
|
||||||
|
|
||||||
case xValue == yValue:
|
|
||||||
x++
|
|
||||||
y++
|
|
||||||
next = appendIfNotAsPrevious(next, xValue)
|
|
||||||
|
|
||||||
case xValue < yValue:
|
|
||||||
next = appendIfNotAsPrevious(next, xValue)
|
|
||||||
x++
|
|
||||||
|
|
||||||
case yValue < xValue:
|
|
||||||
next = appendIfNotAsPrevious(next, yValue)
|
|
||||||
y++
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
releaseSegments(current)
|
|
||||||
current = next
|
|
||||||
}
|
|
||||||
|
|
||||||
out = append(out, current...)
|
|
||||||
releaseSegments(current)
|
|
||||||
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func reverseSegments(input []int) {
|
func reverseSegments(input []int) {
|
||||||
l := len(input)
|
l := len(input)
|
||||||
m := l / 2
|
m := l / 2
|
||||||
|
|
56
todo.txt
56
todo.txt
|
@ -1,32 +1,26 @@
|
||||||
benchmark | old ns/op | new ns/op | delta
|
benchmark old ns/op new ns/op delta
|
||||||
-----------------------------------------------|-----------|-------------|-----------
|
|
||||||
BenchmarkAllGlobMatch-4 512 711 +38.87%
|
|
||||||
BenchmarkMultipleGlobMatch-4 121 417 +244.63%
|
|
||||||
BenchmarkAlternativesGlobMatch-4 166 300 +80.72%
|
|
||||||
BenchmarkAlternativesSuffixFirstGlobMatch-4 23.5 292 +1142.55%
|
|
||||||
BenchmarkAlternativesSuffixSecondGlobMatch-4 29.8 355 +1091.28%
|
|
||||||
BenchmarkAlternativesCombineLiteGlobMatch-4 161 250 +55.28%
|
|
||||||
BenchmarkAlternativesCombineHardGlobMatch-4 325 334 +2.77%
|
|
||||||
BenchmarkPlainGlobMatch-4 7.20 154 +2038.89%
|
|
||||||
BenchmarkPrefixGlobMatch-4 8.75 113 +1191.43%
|
|
||||||
BenchmarkSuffixGlobMatch-4 9.07 115 +1167.92%
|
|
||||||
BenchmarkPrefixSuffixGlobMatch-4 15.1 125 +727.81%
|
|
||||||
|
|
||||||
|
BenchmarkAllGlobMatch-4 519 1024 +97.30%
|
||||||
|
BenchmarkMultipleGlobMatch-4 123 218 +77.24%
|
||||||
|
BenchmarkAlternativesGlobMatch-4 164 283 +72.56%
|
||||||
|
BenchmarkAlternativesSuffixFirstGlobMatch-4 23.6 23.5 -0.42%
|
||||||
BenchmarkIndexPrefix-4 85.1 55.9 -34.31%
|
BenchmarkAlternativesSuffixSecondGlobMatch-4 29.7 30.1 +1.35%
|
||||||
BenchmarkIndexRange-4 170(143) 60.6 -64.35%
|
BenchmarkAlternativesCombineLiteGlobMatch-4 161 352 +118.63%
|
||||||
BenchmarkRowIndex-4 172(128) 94.0 -45.35%
|
BenchmarkAlternativesCombineHardGlobMatch-4 321 649 +102.18%
|
||||||
BenchmarkIndexSingle-4 61.0(16) 35.8 -41.31%
|
BenchmarkPlainGlobMatch-4 7.17 7.09 -1.12%
|
||||||
BenchmarkIndexSuffix-4 84.8 55.7 -34.32%
|
BenchmarkPrefixGlobMatch-4 8.74 8.64 -1.14%
|
||||||
BenchmarkIndexSuper-4 461(180) 192 -58.35%
|
BenchmarkSuffixGlobMatch-4 10.3 9.06 -12.04%
|
||||||
BenchmarkIndexText-4 84.6 54.4 -35.70%
|
BenchmarkPrefixSuffixGlobMatch-4 31.0 15.1 -51.29%
|
||||||
BenchmarkIndexPrefixSuffix-4 84.3 57.2 -32.15%
|
BenchmarkIndexAny-4 1414 232 -83.59%
|
||||||
BenchmarkIndexNothing-4 452(3.31) 92.8 -79.47% XXX
|
BenchmarkIndexContains-4 557 250 -55.12%
|
||||||
BenchmarkIndexMin-4 516(274) 161 -68.80%
|
BenchmarkIndexList-4 207 42.6 -79.42%
|
||||||
BenchmarkIndexMax-4 442(88) 92.4 -79.10%
|
BenchmarkIndexMax-4 630 111 -82.38%
|
||||||
BenchmarkIndexList-4 151(41) 51.1 -66.16%
|
BenchmarkIndexMin-4 515 328 -36.31%
|
||||||
BenchmarkIndexContains-4 492(220) 247 -49.80%
|
BenchmarkIndexPrefixSuffix-4 97.9 86.2 -11.95%
|
||||||
BenchmarkIndexAny-4 887(222) 255 -71.25%
|
BenchmarkIndexPrefix-4 86.1 84.0 -2.44%
|
||||||
|
BenchmarkIndexRange-4 181 144 -20.44%
|
||||||
|
BenchmarkRowIndex-4 185 127 -31.35%
|
||||||
|
BenchmarkIndexSingle-4 82.6 16.0 -80.63%
|
||||||
|
BenchmarkIndexSuffix-4 85.5 84.9 -0.70%
|
||||||
|
BenchmarkIndexSuper-4 450 196 -56.44%
|
||||||
|
BenchmarkIndexText-4 85.3 85.9 +0.70%
|
||||||
|
|
Loading…
Reference in New Issue