File: match_test.go

package info (click to toggle)
golang-github-gobwas-glob 0.2.3%2Bgit20181002.e7a84e9-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 364 kB
  • sloc: sh: 20; makefile: 3
file content (90 lines) | stat: -rw-r--r-- 1,529 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package match

import (
	"reflect"
	"testing"
	"unicode/utf8"
)

var bench_separators = []rune{'.'}

const bench_pattern = "abcdefghijklmnopqrstuvwxyz0123456789"

func TestAppendMerge(t *testing.T) {
	for id, test := range []struct {
		segments [2][]int
		exp      []int
	}{
		{
			[2][]int{
				{0, 6, 7},
				{0, 1, 3},
			},
			[]int{0, 1, 3, 6, 7},
		},
		{
			[2][]int{
				{0, 1, 3, 6, 7},
				{0, 1, 10},
			},
			[]int{0, 1, 3, 6, 7, 10},
		},
	} {
		act := appendMerge(test.segments[0], test.segments[1])
		if !reflect.DeepEqual(act, test.exp) {
			t.Errorf("#%d merge sort segments unexpected:\nact: %v\nexp:%v", id, act, test.exp)
			continue
		}
	}
}

func BenchmarkAppendMerge(b *testing.B) {
	s1 := []int{0, 1, 3, 6, 7}
	s2 := []int{0, 1, 3}

	for i := 0; i < b.N; i++ {
		appendMerge(s1, s2)
	}
}

func BenchmarkAppendMergeParallel(b *testing.B) {
	s1 := []int{0, 1, 3, 6, 7}
	s2 := []int{0, 1, 3}

	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			appendMerge(s1, s2)
		}
	})
}

func BenchmarkReverse(b *testing.B) {
	for i := 0; i < b.N; i++ {
		reverseSegments([]int{1, 2, 3, 4})
	}
}

func getTable() []int {
	table := make([]int, utf8.MaxRune+1)
	for i := 0; i <= utf8.MaxRune; i++ {
		table[i] = utf8.RuneLen(rune(i))
	}

	return table
}

var table = getTable()

const runeToLen = 'q'

func BenchmarkRuneLenFromTable(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_ = table[runeToLen]
	}
}

func BenchmarkRuneLenFromUTF8(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_ = utf8.RuneLen(runeToLen)
	}
}