File tree 4 files changed +181
-0
lines changed
4 files changed +181
-0
lines changed Original file line number Diff line number Diff line change @@ -23,4 +23,20 @@ BenchmarkListComprehensionShort10-16 71486 98007 ns/op
23
23
BenchmarkListComprehensionShort1-16 110869 55206 ns/op
24
24
PASS
25
25
ok github.com/harpratap/cue-perf-tests 33.884s
26
+ ```
27
+
28
+ ## 2. Conjunctions
29
+
30
+ Conjunctions are like AND operators used for specifying multiple constraints. But using too many constraints slows down the export timings too. Meaning ` #level1 & { text1: text2: "hello" } ` is less costly than ` #level1 & { text1: #level2 & { text2: "hello" } ` even though both behave exactly the same.
31
+
32
+ ```
33
+ go test -bench=BenchmarkConjunction -benchtime=5s
34
+ goos: darwin
35
+ goarch: amd64
36
+ pkg: github.com/harpratap/cue-perf-tests
37
+ cpu: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
38
+ BenchmarkConjunctionDouble-16 17859 335044 ns/op
39
+ BenchmarkConjunctionSingle-16 19837 287302 ns/op
40
+ PASS
41
+ ok github.com/harpratap/cue-perf-tests 25.784s
26
42
```
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+
6
+ "cuelang.org/go/cue"
7
+ "cuelang.org/go/cue/cuecontext"
8
+ )
9
+
10
+ const conjunctionSchema = `
11
+ #level1: {
12
+ text1: #level2
13
+ }
14
+
15
+ #level2: {
16
+ text2: string
17
+ }
18
+ `
19
+
20
+ const singleConjunctionVal = `
21
+ v1: #level1 & {
22
+ text1: text2: "hello"
23
+ }
24
+
25
+ v2: #level1 & {
26
+ text1: text2: "hello"
27
+ }
28
+
29
+ v3: #level1 & {
30
+ text1: text2: "hello"
31
+ }
32
+
33
+ v4: #level1 & {
34
+ text1: text2: "hello"
35
+ }
36
+
37
+ v5: #level1 & {
38
+ text1: text2: "hello"
39
+ }
40
+
41
+ v6: #level1 & {
42
+ text1: text2: "hello"
43
+ }
44
+
45
+ v7: #level1 & {
46
+ text1: text2: "hello"
47
+ }
48
+
49
+ v8: #level1 & {
50
+ text1: text2: "hello"
51
+ }
52
+
53
+ v9: #level1 & {
54
+ text1: text2: "hello"
55
+ }
56
+
57
+ v10: #level1 & {
58
+ text1: text2: "hello"
59
+ }
60
+ `
61
+
62
+ const doubleConjunctionVal = `
63
+ v1: #level1 & {
64
+ text1: #level2 & {
65
+ text2: "hello"
66
+ }
67
+ }
68
+
69
+ v2: #level1 & {
70
+ text1: #level2 & {
71
+ text2: "hello"
72
+ }
73
+ }
74
+
75
+ v3: #level1 & {
76
+ text1: #level2 & {
77
+ text2: "hello"
78
+ }
79
+ }
80
+
81
+ v4: #level1 & {
82
+ text1: #level2 & {
83
+ text2: "hello"
84
+ }
85
+ }
86
+
87
+ v5: #level1 & {
88
+ text1: #level2 & {
89
+ text2: "hello"
90
+ }
91
+ }
92
+
93
+ v6: #level1 & {
94
+ text1: #level2 & {
95
+ text2: "hello"
96
+ }
97
+ }
98
+
99
+ v7: #level1 & {
100
+ text1: #level2 & {
101
+ text2: "hello"
102
+ }
103
+ }
104
+
105
+ v8: #level1 & {
106
+ text1: #level2 & {
107
+ text2: "hello"
108
+ }
109
+ }
110
+
111
+ v9: #level1 & {
112
+ text1: #level2 & {
113
+ text2: "hello"
114
+ }
115
+ }
116
+
117
+ v10: #level1 & {
118
+ text1: #level2 & {
119
+ text2: "hello"
120
+ }
121
+ }
122
+ `
123
+
124
+ func conjunctionSingle () {
125
+ var (
126
+ c * cue.Context
127
+ s cue.Value
128
+ v cue.Value
129
+ )
130
+ c = cuecontext .New ()
131
+ s = c .CompileString (conjunctionSchema )
132
+ v = c .CompileString (singleConjunctionVal , cue .Scope (s ))
133
+ fmt .Sprint (v )
134
+ }
135
+
136
+ func conjunctionDouble () {
137
+ var (
138
+ c * cue.Context
139
+ s cue.Value
140
+ v cue.Value
141
+ )
142
+ c = cuecontext .New ()
143
+ s = c .CompileString (conjunctionSchema )
144
+ v = c .CompileString (doubleConjunctionVal , cue .Scope (s ))
145
+ fmt .Sprint (v )
146
+ }
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "testing"
5
+ )
6
+
7
+ func BenchmarkConjunctionDouble (b * testing.B ) {
8
+ for n := 0 ; n < b .N ; n ++ {
9
+ conjunctionDouble ()
10
+ }
11
+ }
12
+
13
+ func BenchmarkConjunctionSingle (b * testing.B ) {
14
+ for n := 0 ; n < b .N ; n ++ {
15
+ conjunctionSingle ()
16
+ }
17
+ }
Original file line number Diff line number Diff line change @@ -5,4 +5,6 @@ func main() {
5
5
listComprehensionLong1 ()
6
6
listComprehensionShort10 ()
7
7
listComprehensionShort10 ()
8
+ conjunctionSingle ()
9
+ conjunctionDouble ()
8
10
}
You can’t perform that action at this time.
0 commit comments