I just happen to allocate a slice of int, of size b.N in my benchmark function.
It is all good for when b.N is:
10000
1000000
100000000
However, when b.N is higher I get:
runtime stack:
runtime.throw(0x6dac98, 0x16)
/usr/local/go/src/runtime/panic.go:616 +0x81
runtime.sysMap(0xc4504b0000, 0x3b9ad0000, 0x0, 0x876f98)
/usr/local/go/src/runtime/mem_linux.go:216 +0x20a
runtime.(*mheap).sysAlloc(0x85c7a0, 0x3b9ad0000, 0x0)
/usr/local/go/src/runtime/malloc.go:470 +0xd4
runtime.(*mheap).grow(0x85c7a0, 0x1dcd65, 0x0)
/usr/local/go/src/runtime/mheap.go:907 +0x60
runtime.(*mheap).allocSpanLocked(0x85c7a0, 0x1dcd65, 0x876fa8, 0x0)
/usr/local/go/src/runtime/mheap.go:820 +0x301
runtime.(*mheap).alloc_m(0x85c7a0, 0x1dcd65, 0xffffffffffff0101, 0x7f959b7fddb8)
/usr/local/go/src/runtime/mheap.go:686 +0x118
runtime.(*mheap).alloc.func1()
/usr/local/go/src/runtime/mheap.go:753 +0x4d
runtime.(*mheap).alloc(0x85c7a0, 0x1dcd65, 0x10101, 0x6e9a28)
/usr/local/go/src/runtime/mheap.go:752 +0x8a
runtime.largeAlloc(0x3b9aca000, 0x450101, 0x456000)
/usr/local/go/src/runtime/malloc.go:826 +0x94
runtime.mallocgc.func1()
/usr/local/go/src/runtime/malloc.go:721 +0x46
runtime.systemstack(0x0)
/usr/local/go/src/runtime/asm_amd64.s:409 +0x79
runtime.mstart()
/usr/local/go/src/runtime/proc.go:1175
What to do ? Can I tell it to not make b.N that high ?
The code benchmarked is a method that searches into an array. I randomly generate this array of size b.N. Should I change this strategy, how to I benchmark this search function ?