Skip to content

Unset a column? #99

Description

@delaneyj
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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions