Skip to content

testing: weird AllocsPerRun return results #47199

Closed
@zigo101

Description

@zigo101

What version of Go are you using (go version)?

$ go version
go version go1.16.6 linux/amd64
go version go1.17rc1 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

Moved from #20021 (comment)

package main

import t "testing"

const N = 1000 * 1000 * 1 // 513
var a [N]byte
var k int

func g(vs ...interface{}) {
	type _ int // avoid g being inlined
	_ = vs[k]
}

func main() {
	{
		x := t.AllocsPerRun(1, func() {
			g(a)
		})
		println(int(x))
	}
	{
		x := t.AllocsPerRun(1, func() {
			g(a, a)
		})
		println(int(x))
	}
	{
		x := t.AllocsPerRun(1, func() {
			g(a, a, a)
		})
		println(int(x))
	}
	{
		x := t.AllocsPerRun(1, func() {
			g(a, a, a, a)
		})
		println(int(x))
	}
	{
		x := t.AllocsPerRun(1, func() {
			g(a, a, a, a, a)
		})
		println(int(x))
	}
}

What did you expect to see?

1 2 3 4 5

What did you see instead?

1 4 3 4 5

If all are removed but the g(a, a, a) case, then it prints 5, which is also weird.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions