gohan/component_test.go

65 lines
893 B
Go
Raw Normal View History

package gohan
import "testing"
type positionComponent struct {
componentID componentID
X, Y float64
}
func (c *positionComponent) ComponentID() componentID {
return c.componentID
}
type velocityComponent struct {
componentID componentID
X, Y float64
}
func (c *velocityComponent) ComponentID() componentID {
return c.componentID
}
func BenchmarkComponent(b *testing.B) {
Reset()
e := NewEntity()
e.AddComponent(&positionComponent{
X: 108,
Y: 0,
})
positionComponentID := componentID(1)
b.StopTimer()
b.ResetTimer()
b.ReportAllocs()
b.StartTimer()
for i := 0; i < b.N; i++ {
_ = e.getComponent(positionComponentID)
}
}
func BenchmarkAddComponent(b *testing.B) {
Reset()
e := NewEntity()
c := &positionComponent{
X: 108,
Y: 0,
}
b.StopTimer()
b.ResetTimer()
b.ReportAllocs()
b.StartTimer()
for i := 0; i < b.N; i++ {
e.AddComponent(c)
}
}