Entity Component System framework for Ebiten
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.1 KiB

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)
}
}