gohan/component_test.go

50 lines
670 B
Go

package gohan
import "testing"
var testComponentID = NewComponentID()
type testComponent struct {
X, Y float64
}
func (t testComponent) ComponentID() ComponentID {
return testComponentID
}
func BenchmarkComponent(b *testing.B) {
e := NewEntity()
e.AddComponent(&testComponent{
X: 108,
Y: 0,
})
b.StopTimer()
b.ResetTimer()
b.ReportAllocs()
b.StartTimer()
for i := 0; i < b.N; i++ {
_ = e.Component(testComponentID)
}
}
func BenchmarkAddComponent(b *testing.B) {
e := NewEntity()
c := &testComponent{
X: 108,
Y: 0,
}
b.StopTimer()
b.ResetTimer()
b.ReportAllocs()
b.StartTimer()
for i := 0; i < b.N; i++ {
e.AddComponent(c)
}
}