-
-
Notifications
You must be signed in to change notification settings - Fork 67
Open
Description
const nPos = 9000
const nPosVel = 1000
func BenchmarkIterColumn(b *testing.B) {
b.StopTimer()
entities := column.NewCollection()
if err := errors.Join(
entities.CreateColumn("px", column.ForFloat64()),
entities.CreateColumn("py", column.ForFloat64()),
entities.CreateColumn("vx", column.ForFloat64()),
entities.CreateColumn("vy", column.ForFloat64()),
entities.CreateColumn("foo", column.ForBool()),
); err != nil {
b.Fatal(err)
}
entities.Query(func(txn *column.Txn) error {
for i := 0; i < nPos; i++ {
_, err := txn.Insert(func(r column.Row) error {
r.SetFloat64("px", 1.0)
r.SetFloat64("py", 2.0)
return nil
})
if err != nil {
return err
}
}
for i := 0; i < nPosVel; i++ {
_, err := txn.Insert(func(r column.Row) error {
r.SetFloat64("px", 1.0)
r.SetFloat64("py", 2.0)
r.SetFloat64("vx", 1.0)
r.SetFloat64("vy", 2.0)
return nil
})
if err != nil {
return err
}
}
return nil
})
b.StartTimer()
for i := 0; i < b.N; i++ {
entities.Query(func(txn *column.Txn) error {
posX := txn.Float64("px")
posY := txn.Float64("py")
velX := txn.Float64("vx")
velY := txn.Float64("vy")
txn.With("px", "py", "vx", "vy").Range(func(idx uint32) {
px, _ := posX.Get()
py, _ := posY.Get()
vx, _ := velX.Get()
vy, _ := velY.Get()
posX.Set(px + vx)
posY.Set(py + vy)
})
return nil
})
}
b.StopTimer()
count := 0
entities.Query(func(txn *column.Txn) error {
count = txn.With("px", "py", "vx", "vy").Count()
return nil
})
assert.Equal(b, nPosVel, count)
}
Note I can add Position and Velocity easily, and the number of PosVel are correct (1000). but how would I then remove the vx/vy
later?
Metadata
Metadata
Assignees
Labels
No labels