json icon indicating copy to clipboard operation
json copied to clipboard

BenchmarkParseNumber in scanner_test.go

Open ivanburak opened this issue 5 years ago • 1 comments

func BenchmarkParseNumber(b *testing.B) {

Hi Dave I think a small change should be done for this func() To see an issue quickly just run this line go test -bench=.Parse.

`

panic: runtime error: index out of range [0] with length 0

goroutine 290 [running]: github.com/pkg/json.BenchmarkParseNumber.func1(0xc000194240) C:/Users/VE/go/dev/src/davecheney/pkg/json-master/scanner_test.go:157 +0x51 testing.(*B).runN(0xc000194240, 0x1) C:/Go/src/testing/benchmark.go:191 +0xf2 testing.(*B).run1.func1(0xc000194240) C:/Go/src/testing/benchmark.go:231 +0x5e created by testing.(*B).run1 C:/Go/src/testing/benchmark.go:224 +0x85 exit status 2 `

// --------------------------------------------------------------------------------------------------------------

`

		for i := 0; i < b.N; i++ {
			r.Seek(0, 0)
			scanner := &Scanner{
				br: byteReader{
					data: buf[:0],
					r:    r,
				},
			}
			scanner.Next()                                       // add scanner.Next() here to escape panic
			n := scanner.parseNumber(scanner.br.window(0)[0])    // panic was here

`

ivanburak avatar Jan 05 '21 16:01 ivanburak

Looks like it was fixed by 00534bc

AlexanderYastrebov avatar Dec 25 '23 12:12 AlexanderYastrebov