-
Notifications
You must be signed in to change notification settings - Fork 26
/
bench_test.go
115 lines (101 loc) · 2.93 KB
/
bench_test.go
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright The KCL Authors. All rights reserved.
package kcl
// KCL_GO_API_TEST_NUM_CPU=1 go test -bench=.
import (
"os"
"sync"
"testing"
)
func BenchmarkValidateCode_hello_1(b *testing.B) {
const N = 1
tBenchValidateCode(b, "./testdata/vet/hello.k.json", "./testdata/vet/hello.k", N)
}
func BenchmarkValidateCode_hello_4(b *testing.B) {
const N = 4
tBenchValidateCode(b, "./testdata/vet/hello.k.json", "./testdata/vet/hello.k", N)
}
func BenchmarkValidateCode_hello_8(b *testing.B) {
const N = 8
tBenchValidateCode(b, "./testdata/vet/hello.k.json", "./testdata/vet/hello.k", N)
}
func BenchmarkValidateCode_sample_1(b *testing.B) {
const N = 1
tBenchValidateCode(b, "./testdata/vet/sample.k.json", "./testdata/vet/sample.k", N)
}
func BenchmarkValidateCode_sample_4(b *testing.B) {
const N = 4
tBenchValidateCode(b, "./testdata/vet/sample.k.json", "./testdata/vet/sample.k", N)
}
func BenchmarkValidateCode_sample_8(b *testing.B) {
const N = 8
tBenchValidateCode(b, "./testdata/vet/sample.k.json", "./testdata/vet/sample.k", N)
}
func tBenchValidateCode(b *testing.B, datafile, codefile string, N int) {
var (
data = tLoadFile(b, datafile)
code = tLoadFile(b, codefile)
)
b.ResetTimer()
var limit = make(chan struct{}, N)
var wg sync.WaitGroup
for i := 0; i < b.N; i++ {
wg.Add(1)
go func() {
defer wg.Done()
limit <- struct{}{}
defer func() { <-limit }()
if _, err := ValidateCode(data, code, nil); err != nil {
_ = err // ignore error
}
}()
}
wg.Wait()
}
func tLoadFile(tb testing.TB, path string) string {
data, err := os.ReadFile(path)
if err != nil {
tb.Fatal(err)
}
return string(data)
}
var listUpDownStreamData = struct {
name string
root string
files []string
upStreams []string
changed []string
downStreams []string
}{
name: "projectA",
root: "./pkg/tools/list/testdata/complicate/",
files: []string{"appops/projectA/base/base.k", "appops/projectA/dev/main.k", "base/render/server/server_render.k"},
upStreams: []string{
"base/frontend/server",
"base/frontend/server/server.k",
"base/frontend/container",
"base/frontend/container/container.k",
"base/frontend/container/container_port.k",
},
changed: []string{"base/frontend/container/container_port.k"},
downStreams: []string{
"base/frontend/container",
"base/frontend/server/server.k",
"base/frontend/server",
"appops/projectA/base",
"appops/projectA/base/base.k",
},
}
func BenchmarkImportDepParser_ListDownStreamFiles(b *testing.B) {
for i := 0; i < b.N; i++ {
if _, err := ListDownStreamFiles(listUpDownStreamData.root, &ListDepsOptions{Files: listUpDownStreamData.files, UpStreams: listUpDownStreamData.changed}); err != nil {
b.Fatal(err)
}
}
}
func BenchmarkImportDepParser_ListUpStreamFiles(b *testing.B) {
for i := 0; i < b.N; i++ {
if _, err := ListUpStreamFiles(listUpDownStreamData.root, &ListDepsOptions{Files: listUpDownStreamData.files}); err != nil {
b.Fatal(err)
}
}
}