-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
testing: weird AllocsPerRun return results #47199
Comments
The benchmark result of the following code is also weird in two points:
package main
import "testing"
var i interface{}
func foo(v int) {
i = v
}
func Benchmark_Foo(b *testing.B) {
for i := 0; i < b.N; i++ {
foo(i)
}
} |
For the first case, I don't think 1 iteration is a good way to get the results you wanted. If you change it to (say) 1000 iterations, it gets 1 2 3 4 5 as expected.
|
I think your second case has to do with the fact that we don't need to allocate when putting values 0-255 in an interface. See |
@go101 as you thumb-up'd the replies it seems your questions are answered. Anything else needs to be addressed on this issue? Thanks. |
For the 2nd case, if what @randall77 described is true, it would be better to use |
We decided against rounding to nearest in #24631 |
Okay. So I will close this issue soon. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
Moved from #20021 (comment)
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.The text was updated successfully, but these errors were encountered: