Debian Codegraph @

benchmark/parse/parse_test.go

raw symbols SCIP
1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package parsescip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/
6
7 import (
8 "reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/"
9 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
10 "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/"
11 )
12
13 func TestParseLinescip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/TestParseLine().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
14 cases := []struct {
15 line string
16 want *Benchmarkscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#
17 err bool // expect an error
18 }{
19 {
20 line: "BenchmarkEncrypt 100000000 19.6 ns/op",
21 want: &Benchmarkscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#{
22 Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Name.: "BenchmarkEncrypt",
23 Nscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#N.: 100000000, NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#NsPerOp.: 19.6,
24 Measuredscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Measured.: NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/NsPerOp.,
25 },
26 },
27 {
28 line: "BenchmarkEncrypt 100000000 19.6 ns/op 817.77 MB/s",
29 want: &Benchmarkscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#{
30 Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Name.: "BenchmarkEncrypt",
31 Nscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#N.: 100000000, NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#NsPerOp.: 19.6, MBPerSscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#MBPerS.: 817.77,
32 Measuredscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Measured.: NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/NsPerOp. | MBPerSscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/MBPerS.,
33 },
34 },
35 {
36 line: "BenchmarkEncrypt 100000000 19.6 ns/op 817.77",
37 want: &Benchmarkscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#{
38 Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Name.: "BenchmarkEncrypt",
39 Nscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#N.: 100000000, NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#NsPerOp.: 19.6,
40 Measuredscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Measured.: NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/NsPerOp.,
41 },
42 },
43 {
44 line: "BenchmarkEncrypt 100000000 19.6 ns/op 817.77 MB/s 5 allocs/op",
45 want: &Benchmarkscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#{
46 Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Name.: "BenchmarkEncrypt",
47 Nscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#N.: 100000000, NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#NsPerOp.: 19.6, MBPerSscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#MBPerS.: 817.77, AllocsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#AllocsPerOp.: 5,
48 Measuredscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Measured.: NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/NsPerOp. | MBPerSscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/MBPerS. | AllocsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/AllocsPerOp.,
49 },
50 },
51 {
52 line: "BenchmarkEncrypt 100000000 19.6 ns/op 817.77 MB/s 3 B/op 5 allocs/op",
53 want: &Benchmarkscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#{
54 Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Name.: "BenchmarkEncrypt",
55 Nscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#N.: 100000000, NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#NsPerOp.: 19.6, MBPerSscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#MBPerS.: 817.77, AllocedBytesPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#AllocedBytesPerOp.: 3, AllocsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#AllocsPerOp.: 5,
56 Measuredscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Measured.: NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/NsPerOp. | MBPerSscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/MBPerS. | AllocedBytesPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/AllocedBytesPerOp. | AllocsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/AllocsPerOp.,
57 },
58 },
59 // error handling cases
60 {
61 line: "BenchPress 100 19.6 ns/op", // non-benchmark
62 err: true,
63 },
64 {
65 line: "BenchmarkEncrypt lots 19.6 ns/op", // non-int iterations
66 err: true,
67 },
68 {
69 line: "BenchmarkBridge 100000000 19.6 smoots", // unknown unit
70 want: &Benchmarkscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#{
71 Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Name.: "BenchmarkBridge",
72 Nscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#N.: 100000000,
73 },
74 },
75 {
76 line: "PASS",
77 err: true,
78 },
79 }
80
81 for _, tt := range cases {
82 have, err := ParseLinescip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/ParseLine().(tt.line)
83 if tt.err && err == nil {
84 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("parsing line %q should have failed", tt.line)
85 continue
86 }
87 if !reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.25.0 reflect/DeepEqual().(have, tt.want) {
88 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("parsed line %q incorrectly, want %v have %v", tt.line, tt.want, have)
89 }
90 }
91 }
92
93 func TestParseSetscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/TestParseSet().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
94 // Test two things:
95 // 1. The noise that can accompany testing.B output gets ignored.
96 // 2. Benchmarks with the same name have their order preserved.
97 in := `
98 ? crypto [no test files]
99 PASS
100 pem_decrypt_test.go:17: test 4. %!s(x509.PEMCipher=5)
101 ... [output truncated]
102
103 BenchmarkEncrypt 100000000 19.6 ns/op
104 BenchmarkEncrypt 5000000 517 ns/op
105 === RUN TestChunk
106 --- PASS: TestChunk (0.00 seconds)
107 --- SKIP: TestLinuxSendfile (0.00 seconds)
108 fs_test.go:716: skipping; linux-only test
109 BenchmarkReadRequestApachebench 1000000 2960 ns/op 27.70 MB/s 839 B/op 9 allocs/op
110 BenchmarkClientServerParallel64 50000 59192 ns/op 7028 B/op 60 allocs/op
111 ok net/http 95.783s
112 `
113
114 want := Setscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Set#{
115 "BenchmarkReadRequestApachebench": []*Benchmarkscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#{
116 {
117 Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Name.: "BenchmarkReadRequestApachebench",
118 Nscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#N.: 1000000, NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#NsPerOp.: 2960, MBPerSscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#MBPerS.: 27.70, AllocedBytesPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#AllocedBytesPerOp.: 839, AllocsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#AllocsPerOp.: 9,
119 Measuredscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Measured.: NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/NsPerOp. | MBPerSscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/MBPerS. | AllocedBytesPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/AllocedBytesPerOp. | AllocsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/AllocsPerOp.,
120 Ordscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Ord.: 2,
121 },
122 },
123 "BenchmarkClientServerParallel64": []*Benchmarkscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#{
124 {
125 Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Name.: "BenchmarkClientServerParallel64",
126 Nscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#N.: 50000, NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#NsPerOp.: 59192, AllocedBytesPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#AllocedBytesPerOp.: 7028, AllocsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#AllocsPerOp.: 60,
127 Measuredscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Measured.: NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/NsPerOp. | AllocedBytesPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/AllocedBytesPerOp. | AllocsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/AllocsPerOp.,
128 Ordscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Ord.: 3,
129 },
130 },
131 "BenchmarkEncrypt": []*Benchmarkscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#{
132 {
133 Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Name.: "BenchmarkEncrypt",
134 Nscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#N.: 100000000, NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#NsPerOp.: 19.6,
135 Measuredscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Measured.: NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/NsPerOp.,
136 Ordscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Ord.: 0,
137 },
138 {
139 Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Name.: "BenchmarkEncrypt",
140 Nscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#N.: 5000000, NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#NsPerOp.: 517,
141 Measuredscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Measured.: NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/NsPerOp.,
142 Ordscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Ord.: 1,
143 },
144 },
145 }
146
147 have, err := ParseSetscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/ParseSet().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(in))
148 if err != nil {
149 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unexpected err during ParseSet: %v", err)
150 }
151 if !reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.25.0 reflect/DeepEqual().(want, have) {
152 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("parsed bench set incorrectly, want %v have %v", want, have)
153 }
154 }
155
156 func TestStringscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/TestString().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
157 tests := []struct {
158 name string
159 input *Benchmarkscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#
160 wanted string
161 }{
162 {
163 name: "nsTest",
164 input: &Benchmarkscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#{
165 Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Name.: "BenchmarkTest",
166 Nscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#N.: 100000000, NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#NsPerOp.: 19.6,
167 Measuredscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Measured.: NsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/NsPerOp.,
168 },
169 wanted: "BenchmarkTest 100000000 19.60 ns/op",
170 },
171 {
172 name: "mbTest",
173 input: &Benchmarkscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#{
174 Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Name.: "BenchmarkTest",
175 Nscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#N.: 100000000, MBPerSscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#MBPerS.: 19.6,
176 Measuredscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Measured.: MBPerSscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/MBPerS.,
177 },
178 wanted: "BenchmarkTest 100000000 19.60 MB/s",
179 },
180 {
181 name: "allocatedBytesTest",
182 input: &Benchmarkscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#{
183 Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Name.: "BenchmarkTest",
184 Nscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#N.: 100000000, AllocedBytesPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#AllocedBytesPerOp.: 5,
185 Measuredscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Measured.: AllocedBytesPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/AllocedBytesPerOp.,
186 },
187 wanted: "BenchmarkTest 100000000 5 B/op",
188 },
189 {
190 name: "allocsTest",
191 input: &Benchmarkscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#{
192 Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Name.: "BenchmarkTest",
193 Nscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#N.: 100000000, AllocsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#AllocsPerOp.: 5,
194 Measuredscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#Measured.: AllocsPerOpscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/AllocsPerOp.,
195 },
196 wanted: "BenchmarkTest 100000000 5 allocs/op",
197 },
198 }
199
200 for _, tt := range tests {
201 t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
202 result := tt.input.Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/benchmark/parse`/Benchmark#String().()
203 if result != tt.wanted {
204 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("String() is called, want %q, have %q", tt.wanted, result)
205 }
206 })
207 }
208 }