github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/bench/iface/iface.go (about)

     1  package iface
     2  
     3  type Interface interface {
     4  	Get() int
     5  	CopyGet() int
     6  	Set(x int)
     7  }
     8  
     9  //go:noinline
    10  func NewStruct(i int) Interface {
    11  	if i == 0 {
    12  		return &Struct{}
    13  	} else {
    14  		return &Struct2{}
    15  	}
    16  }
    17  
    18  type Struct struct {
    19  	x int
    20  }
    21  
    22  func (s Struct) CopyGet() int {
    23  	return s.x
    24  }
    25  
    26  func (s *Struct) Get() int {
    27  	return s.x
    28  }
    29  
    30  func (s *Struct) Set(x int) {
    31  	s.x = x
    32  }
    33  
    34  type Struct2 struct {
    35  	x int
    36  }
    37  
    38  func (s Struct2) CopyGet() int {
    39  	return s.x
    40  }
    41  
    42  func (s *Struct2) Get() int {
    43  	return s.x
    44  }
    45  
    46  func (s *Struct2) Set(x int) {
    47  	s.x = x
    48  }