Skip to content

Commit

Permalink
write add/remove benchmark for uot ecs
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange-42 committed Jan 9, 2024
1 parent 118e12c commit 41a49cb
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 3 deletions.
94 changes: 94 additions & 0 deletions benchmark/competition/add_remove/uot_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package addremove

import (
"testing"

"github.com/unitoftime/ecs"
)

func BenchmarkIterUot(b *testing.B) {
b.StopTimer()
world := ecs.NewWorld()

queryPos := ecs.Query1[Position](world)
queryPosVel := ecs.Query2[Position, Velocity](world)
comp := ecs.C(Velocity{0, 0})

for i := 0; i < nEntities; i++ {
id := world.NewId()
ecs.Write(world, id,
ecs.C(Position{0, 0}),
)
}

entities := make([]ecs.Id, 0, nEntities)

// Iterate once for more fairness
queryPos.MapId(func(id ecs.Id, pos *Position) {
entities = append(entities, id)
})

for _, e := range entities {
ecs.Write(world, e,
ecs.C(Velocity{0, 0}),
)
}

entities = entities[:0]

queryPosVel.MapId(func(id ecs.Id, pos *Position, vel *Velocity) {
entities = append(entities, id)
})

for _, e := range entities {
ecs.DeleteComponent(world, e, comp)
}

entities = entities[:0]

b.StartTimer()

for i := 0; i < b.N; i++ {

queryPos.MapId(func(id ecs.Id, pos *Position) {
entities = append(entities, id)
})

for _, e := range entities {
ecs.Write(world, e,
ecs.C(Velocity{0, 0}),
)
}

entities = entities[:0]

queryPosVel.MapId(func(id ecs.Id, pos *Position, vel *Velocity) {
entities = append(entities, id)
})

for _, e := range entities {
ecs.DeleteComponent(world, e, comp)
}

entities = entities[:0]
}
}

func BenchmarkBuildUot(b *testing.B) {
for i := 0; i < b.N; i++ {
world := ecs.NewWorld()

for i := 0; i < nEntities; i++ {
id := world.NewId()
ecs.Write(world, id,
ecs.C(Position{0, 0}),
)
}

queryPos := ecs.Query1[Position](world)
queryPosVel := ecs.Query2[Position, Velocity](world)

_ = queryPos
_ = queryPosVel
}
}
2 changes: 1 addition & 1 deletion benchmark/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/marioolofo/go-gameengine-ecs v0.9.0
github.com/mlange-42/arche v0.9.0
github.com/pkg/profile v1.7.0
github.com/unitoftime/ecs v0.0.1
github.com/unitoftime/ecs v0.0.2-0.20240109122000-af4227c75194
github.com/wfranczyk/ento v0.1.0
github.com/yohamta/donburi v1.3.4
)
Expand Down
4 changes: 2 additions & 2 deletions benchmark/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/unitoftime/cod v0.0.0-20230616173404-085cf4fe3918 h1:C1W4LPOwKCBq0cAzb81508ePBIfAR9ecP9GBR5zi/AI=
github.com/unitoftime/cod v0.0.0-20230616173404-085cf4fe3918/go.mod h1:Iufibv9gn5GJb4Qzkf8e8xaXOV77OgkrB5kkBZTEN+M=
github.com/unitoftime/ecs v0.0.1 h1:xYxtSz99Ys5Cd/BgA54/ajC9Rp3t4tGmcM7Q8uIeDMc=
github.com/unitoftime/ecs v0.0.1/go.mod h1:3i8ercdQPj5M8lq9B3qGjywG7RRq0tBjbP/7THI5mtc=
github.com/unitoftime/ecs v0.0.2-0.20240109122000-af4227c75194 h1:JRt/yW/9TA3VZasAexsKDzaQpeFDEoZf1U9a0OuupAA=
github.com/unitoftime/ecs v0.0.2-0.20240109122000-af4227c75194/go.mod h1:3i8ercdQPj5M8lq9B3qGjywG7RRq0tBjbP/7THI5mtc=
github.com/wfranczyk/ento v0.1.0 h1:BMuty7VOn8qNp7EbUhlimQXnckuwrjuJSgJ46NFdk2E=
github.com/wfranczyk/ento v0.1.0/go.mod h1:oiJdFEvu66RU8kZwEySB/xfizPLQ/maChXwYPxY3l9o=
github.com/yohamta/donburi v1.3.4 h1:u/Wa+JA9/c/73J9eAvUZgomvbhpl0jZXagM4sjSNImw=
Expand Down

0 comments on commit 41a49cb

Please sign in to comment.