Skip to content

Commit

Permalink
Add benchmarks for world component access with shuffled entities (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange-42 authored Apr 20, 2023
1 parent 6acf3a5 commit 500fcfb
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* Tweak/improve example `batch_ops` (#222)
* Adds an example for running simulations in parallel (#223)

### Other

* Adds benchmarks for world component access with shuffled entities (#224)

## [[v0.7.0]](https://github.com/mlange-42/arche/compare/v0.6.3...v0.7.0)

### Features
Expand Down
71 changes: 71 additions & 0 deletions benchmark/arche/iterate_world/arche_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package iterate

import (
"math/rand"
"testing"

c "github.com/mlange-42/arche/benchmark/arche/common"
Expand Down Expand Up @@ -96,6 +97,52 @@ func runArcheWorldGetGenericUnchecked(b *testing.B, count int) {
}
}

func runArcheWorldGetUncheckedShuffled(b *testing.B, count int) {
b.StopTimer()
world := ecs.NewWorld()

posID := ecs.ComponentID[c.Position](&world)
rotID := ecs.ComponentID[c.Rotation](&world)

entities := make([]ecs.Entity, count)
for i := 0; i < count; i++ {
entities[i] = world.NewEntity(posID, rotID)
}
rand.Shuffle(len(entities), func(i, j int) { entities[i], entities[j] = entities[j], entities[i] })
b.StartTimer()

for i := 0; i < b.N; i++ {
for _, e := range entities {
pos := (*c.Position)(world.GetUnchecked(e, posID))
pos.X = 1
}
}
}

func runArcheWorldGetGenericUncheckedShuffled(b *testing.B, count int) {
b.StopTimer()
world := ecs.NewWorld()

posID := ecs.ComponentID[c.Position](&world)
rotID := ecs.ComponentID[c.Rotation](&world)

get := generic.NewMap1[c.Position](&world)

entities := make([]ecs.Entity, count)
for i := 0; i < count; i++ {
entities[i] = world.NewEntity(posID, rotID)
}
rand.Shuffle(len(entities), func(i, j int) { entities[i], entities[j] = entities[j], entities[i] })
b.StartTimer()

for i := 0; i < b.N; i++ {
for _, e := range entities {
pos := get.GetUnchecked(e)
pos.X = 1
}
}
}

func BenchmarkArcheIterWorldID_1_000(b *testing.B) {
runArcheWorldGet(b, 1000)
}
Expand Down Expand Up @@ -143,3 +190,27 @@ func BenchmarkArcheIterWorldGenericUnchecked_10_000(b *testing.B) {
func BenchmarkArcheIterWorldGenericUnchecked_100_000(b *testing.B) {
runArcheWorldGetGenericUnchecked(b, 100000)
}

func BenchmarkArcheIterWorldIDUncheckedShuffled_1_000(b *testing.B) {
runArcheWorldGetUncheckedShuffled(b, 1000)
}

func BenchmarkArcheIterWorldIDUncheckedShuffled_10_000(b *testing.B) {
runArcheWorldGetUncheckedShuffled(b, 10000)
}

func BenchmarkArcheIterWorldIDUncheckedShuffled_100_000(b *testing.B) {
runArcheWorldGetUncheckedShuffled(b, 100000)
}

func BenchmarkArcheIterWorldGenericUncheckedShuffled_1_000(b *testing.B) {
runArcheWorldGetGenericUncheckedShuffled(b, 1000)
}

func BenchmarkArcheIterWorldGenericUncheckedShuffled_10_000(b *testing.B) {
runArcheWorldGetGenericUncheckedShuffled(b, 10000)
}

func BenchmarkArcheIterWorldGenericUncheckedShuffled_100_000(b *testing.B) {
runArcheWorldGetGenericUncheckedShuffled(b, 100000)
}

0 comments on commit 500fcfb

Please sign in to comment.