//The idea of this benchmark is to determine the // performance cost of when we pass around interfaces // instead of the concrete struct and getting a field // on the struct vs calling a `get` method on the // interface package test import ( "testing" ) var ( globalInt64 int64 usr *user = &user{25} iUser User = usr ) type User interface { GetId() int64 } type user struct { Id int64 } func (u *user) GetId() int64 { return u.Id } func BenchmarkStructField(b *testing.B) { var g int64 for n := 0; n < b.N; n++ { g = usr.Id if g > 24 { g = 0 } } globalInt64 = g } func BenchmarkInterfaceMethod(b *testing.B) { var g int64 for n := 0; n < b.N; n++ { g = iUser.GetId() if g > 24 { g = 0 } } globalInt64 = g }