You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
893 B
Go
65 lines
893 B
Go
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)
|
|
}
|
|
}
|