Skip to content

Commit 23b2040

Browse files
committed
reflect: add benchmark for method call
Signed-off-by: Ignacio Hagopian <[email protected]>
1 parent 3dd5867 commit 23b2040

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/reflect/all_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,26 @@ func BenchmarkCall(b *testing.B) {
19421942
})
19431943
}
19441944

1945+
type myint int64
1946+
1947+
type inccer interface {
1948+
inc()
1949+
}
1950+
1951+
func (i *myint) inc() {
1952+
*i = *i + 1
1953+
}
1954+
1955+
func BenchmarkCallMethod(b *testing.B) {
1956+
b.ReportAllocs()
1957+
z := inccer(new(myint))
1958+
1959+
v := ValueOf(z.inc)
1960+
for i := 0; i < b.N; i++ {
1961+
v.Call(nil)
1962+
}
1963+
}
1964+
19451965
func BenchmarkCallArgCopy(b *testing.B) {
19461966
byteArray := func(n int) Value {
19471967
return Zero(ArrayOf(n, TypeOf(byte(0))))

0 commit comments

Comments
 (0)