@@ -5,61 +5,47 @@ import (
55 "testing"
66)
77
8- func BenchmarkPosVelQuery_1000 (b * testing.B ) {
8+ func BenchmarkPosVelQueryInline_1000 (b * testing.B ) {
99 n := 1000
1010 world := NewWorld (1024 )
1111
1212 mapper := NewMap2 [Position , Velocity ](& world )
1313 mapper .NewBatch (n , & Position {}, & Velocity {X : 1 , Y : 0 })
1414
1515 filter := NewFilter2 [Position , Velocity ](& world )
16- for b . Loop ( ) {
16+ loop := func ( filter * Filter2 [ Position , Velocity ] ) {
1717 query := filter .Query ()
1818 for query .Next () {
1919 pos , vel := query .Get ()
2020 pos .X += vel .X
2121 pos .Y += vel .Y
2222 }
2323 }
24+
25+ for b .Loop () {
26+ loop (filter )
27+ }
2428}
2529
26- func BenchmarkPosVelQueryCached_1000 (b * testing.B ) {
27- n := 1000
30+ func BenchmarkPosVelQueryInline_100k (b * testing.B ) {
31+ n := 100_000
2832 world := NewWorld (1024 )
2933
3034 mapper := NewMap2 [Position , Velocity ](& world )
3135 mapper .NewBatch (n , & Position {}, & Velocity {X : 1 , Y : 0 })
3236
33- filter := NewFilter2 [Position , Velocity ](& world ). Register ()
34- for b . Loop ( ) {
37+ filter := NewFilter2 [Position , Velocity ](& world )
38+ loop := func ( filter * Filter2 [ Position , Velocity ] ) {
3539 query := filter .Query ()
3640 for query .Next () {
3741 pos , vel := query .Get ()
3842 pos .X += vel .X
3943 pos .Y += vel .Y
4044 }
4145 }
42- }
43-
44- func BenchmarkPosVelQueryUnsafe_1000 (b * testing.B ) {
45- n := 1000
46- world := NewWorld (1024 )
47-
48- posID := ComponentID [Position ](& world )
49- velID := ComponentID [Velocity ](& world )
5046
51- mapper := NewMap2 [Position , Velocity ](& world )
52- mapper .NewBatch (n , & Position {}, & Velocity {X : 1 , Y : 0 })
53-
54- filter := NewUnsafeFilter (& world , posID , velID )
5547 for b .Loop () {
56- query := filter .Query ()
57- for query .Next () {
58- pos := (* Position )(query .Get (posID ))
59- vel := (* Velocity )(query .Get (velID ))
60- pos .X += vel .X
61- pos .Y += vel .Y
62- }
48+ loop (filter )
6349 }
6450}
6551
@@ -120,6 +106,46 @@ func BenchmarkPosVelQueryParallel4_100k(b *testing.B) {
120106 }
121107}
122108
109+ func BenchmarkPosVelQueryCached_1000 (b * testing.B ) {
110+ n := 1000
111+ world := NewWorld (1024 )
112+
113+ mapper := NewMap2 [Position , Velocity ](& world )
114+ mapper .NewBatch (n , & Position {}, & Velocity {X : 1 , Y : 0 })
115+
116+ filter := NewFilter2 [Position , Velocity ](& world ).Register ()
117+ for b .Loop () {
118+ query := filter .Query ()
119+ for query .Next () {
120+ pos , vel := query .Get ()
121+ pos .X += vel .X
122+ pos .Y += vel .Y
123+ }
124+ }
125+ }
126+
127+ func BenchmarkPosVelQueryUnsafe_1000 (b * testing.B ) {
128+ n := 1000
129+ world := NewWorld (1024 )
130+
131+ posID := ComponentID [Position ](& world )
132+ velID := ComponentID [Velocity ](& world )
133+
134+ mapper := NewMap2 [Position , Velocity ](& world )
135+ mapper .NewBatch (n , & Position {}, & Velocity {X : 1 , Y : 0 })
136+
137+ filter := NewUnsafeFilter (& world , posID , velID )
138+ for b .Loop () {
139+ query := filter .Query ()
140+ for query .Next () {
141+ pos := (* Position )(query .Get (posID ))
142+ vel := (* Velocity )(query .Get (velID ))
143+ pos .X += vel .X
144+ pos .Y += vel .Y
145+ }
146+ }
147+ }
148+
123149func BenchmarkPosVelMap_1000 (b * testing.B ) {
124150 n := 1000
125151 world := NewWorld (1024 )
0 commit comments