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.
49 lines
670 B
49 lines
670 B
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) |
|
} |
|
}
|
|
|