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) { w := NewWorld() e := w.NewEntity() positionComponentID := w.NewComponentID() w.AddComponent(e, &positionComponent{ X: 108, Y: 0, componentID: positionComponentID, }) b.StopTimer() b.ResetTimer() b.ReportAllocs() b.StartTimer() for i := 0; i < b.N; i++ { _ = w.Component(e, positionComponentID) } } func BenchmarkAddComponent(b *testing.B) { w := NewWorld() e := w.NewEntity() positionComponentID := w.NewComponentID() c := &positionComponent{ X: 108, Y: 0, componentID: positionComponentID, } b.StopTimer() b.ResetTimer() b.ReportAllocs() b.StartTimer() for i := 0; i < b.N; i++ { w.AddComponent(e, c) } }