File tree 1 file changed +20
-4
lines changed
1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -176,10 +176,26 @@ func BenchmarkInitOnly(b *testing.B) {
176
176
}
177
177
}
178
178
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
+
183
199
func BenchmarkParseAndReset (b * testing.B ) {
184
200
pegs := make ([]* Peg [uint32 ], len (pegFileContents ))
185
201
for i , content := range pegFileContents {
You can’t perform that action at this time.
0 commit comments