}
}
+type S struct {
+ i1 int64
+ i2 int64
+}
+
+func BenchmarkInterfaceBig(b *testing.B) {
+ v := ValueOf(S{})
+ for i := 0; i < b.N; i++ {
+ v.Interface()
+ }
+ b.StopTimer()
+}
+
+func TestAllocsInterfaceBig(t *testing.T) {
+ v := ValueOf(S{})
+ if allocs := testing.AllocsPerRun(100, func() { v.Interface() }); allocs > 0 {
+ t.Errorf("allocs:", allocs)
+ }
+}
+
+func BenchmarkInterfaceSmall(b *testing.B) {
+ v := ValueOf(int64(0))
+ for i := 0; i < b.N; i++ {
+ v.Interface()
+ }
+}
+
+func TestAllocsInterfaceSmall(t *testing.T) {
+ v := ValueOf(int64(0))
+ if allocs := testing.AllocsPerRun(100, func() { v.Interface() }); allocs > 0 {
+ t.Errorf("allocs:", allocs)
+ }
+}
+
// An exhaustive is a mechanism for writing exhaustive or stochastic tests.
// The basic usage is:
//
eface.typ = v.typ
eface.word = v.iword()
- if v.flag&flagIndir != 0 && v.typ.size > ptrSize {
+ // Don't need to allocate if v is not addressable or fits in one word.
+ if v.flag&flagAddr != 0 && v.typ.size > ptrSize {
// eface.word is a pointer to the actual data,
// which might be changed. We need to return
// a pointer to unchanging data, so make a copy.