Skip to content

Commit b00eaae

Browse files
committed
Add back parse only benchmark
* Fixed in Go 1.24.2. see golang/go#72934
1 parent 9c1e2c6 commit b00eaae

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

Diff for: peg_test.go

+20-4
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,26 @@ func BenchmarkInitOnly(b *testing.B) {
176176
}
177177
}
178178

179-
// Only measuring parse because enclosing peg.Reset() with
180-
// b.StopTimer() and b.StartTimer() is too fast for the
181-
// benchmarker.
182-
// See https://stackoverflow.com/questions/37620251/golang-benchmarking-b-stoptimer-hangs-is-it-me
179+
func BenchmarkParse(b *testing.B) {
180+
pegs := make([]*Peg[uint32], len(pegFileContents))
181+
for i, content := range pegFileContents {
182+
p := &Peg[uint32]{Tree: tree.New(true, true, false), Buffer: content}
183+
_ = p.Init(Size[uint32](1 << 15))
184+
pegs[i] = p
185+
}
186+
187+
for b.Loop() {
188+
for _, peg := range pegs {
189+
if err := peg.Parse(); err != nil {
190+
b.Fatal(err)
191+
}
192+
b.StopTimer()
193+
peg.Reset()
194+
b.StartTimer()
195+
}
196+
}
197+
}
198+
183199
func BenchmarkParseAndReset(b *testing.B) {
184200
pegs := make([]*Peg[uint32], len(pegFileContents))
185201
for i, content := range pegFileContents {

0 commit comments

Comments
 (0)