Skip to content

BenchmarkParseNumber in scanner_test.go #8

Open
@ivanburak

Description

@ivanburak

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

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions