Skip to content

Commit

Permalink
cleanup benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
kelindar committed Jul 13, 2021
1 parent 423f120 commit b1bb999
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 50 deletions.
4 changes: 2 additions & 2 deletions collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,14 @@ func (c *Collection) Query(fn func(txn *Txn) error) error {
// Execute the query and keep the error for later
if err := fn(txn); err != nil {
txn.rollback()
txn.release()
c.txns.release(txn)
return err
}

// Now that the iteration has finished, we can range over the pending action
// queue and apply all of the actions that were requested by the Selector.
txn.commit()
txn.release()
c.txns.release(txn)
return nil
}

Expand Down
62 changes: 26 additions & 36 deletions collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,53 +21,43 @@ import (
"github.com/stretchr/testify/assert"
)

/*
BenchmarkCollection/insert-8 5439637 221.3 ns/op 18 B/op 0 allocs/op
BenchmarkCollection/fetch-8 23985608 48.55 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/scan-8 1845 689796 ns/op 25 B/op 0 allocs/op
BenchmarkCollection/count-8 1000000 1133 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/range-8 10000 107436 ns/op 10 B/op 0 allocs/op
BenchmarkCollection/update-at-8 4171920 286.7 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/update-all-8 837 1312193 ns/op 52392 B/op 0 allocs/op
BenchmarkCollection/delete-at-8 7141628 169.9 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/delete-all-8 189722 6322 ns/op 0 B/op 0 allocs/op
*/

/*
cpu: Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
BenchmarkCollection/insert-8 3047058 391.1 ns/op 104 B/op 1 allocs/op
BenchmarkCollection/fetch-8 27255073 44.56 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/scan-8 1724 719894 ns/op 796 B/op 3 allocs/op
BenchmarkCollection/count-8 750037 1623 ns/op 1 B/op 0 allocs/op
BenchmarkCollection/range-8 10000 105780 ns/op 109 B/op 0 allocs/op
BenchmarkCollection/update-at-8 2178361 553.4 ns/op 64 B/op 1 allocs/op
BenchmarkCollection/update-all-8 758 1544390 ns/op 1965 B/op 12 allocs/op
BenchmarkCollection/delete-at-8 3913665 302.0 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/delete-all-8 1000000 1010 ns/op 1 B/op 0 allocs/op
BenchmarkCollection/insert-8 1785 630707 ns/op 698 B/op 0 allocs/op
BenchmarkCollection/fetch-8 25532186 45.79 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/scan-8 1574 757025 ns/op 12 B/op 0 allocs/op
BenchmarkCollection/count-8 769180 1596 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/range-8 10000 107451 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/update-at-8 2354398 506.9 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/update-all-8 730 1544794 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/delete-at-8 3883114 306.7 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/delete-all-8 1000000 1001 ns/op 0 B/op 0 allocs/op
*/
func BenchmarkCollection(b *testing.B) {
amount := 100000
players := loadPlayers(amount)
obj := Object{
"name": "Roman",
"age": 35,
"wallet": 50.99,
"health": 100,
"mana": 200,
}

b.Run("insert", func(b *testing.B) {
col := NewCollection()
temp := loadPlayers(500)
data := loadFixture("players.json")
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
col.Insert(obj)
if col.Count() >= 1000 {
col = NewCollection()
}
b.StopTimer()
temp.Query(func(txn *Txn) error {
txn.DeleteAll()
return nil
})
b.StartTimer()

temp.Query(func(txn *Txn) error {
for _, p := range data {
txn.Insert(p)
}
return nil
})
}
})

amount := 100000
players := loadPlayers(amount)
b.Run("fetch", func(b *testing.B) {
name := ""
b.ReportAllocs()
Expand Down
14 changes: 2 additions & 12 deletions txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (p *txnPool) acquirePage(columnName string) (page *commit.Buffer) {
select {
case page = <-p.pages:
default:
page = &commit.Buffer{}
page = commit.NewBuffer(chunkSize)
}

// Initialize
Expand Down Expand Up @@ -189,12 +189,6 @@ func (txn *Txn) WithFloat(column string, predicate func(v float64) bool) *Txn {
return txn
}

/* ESCAPES
.\txn.go:157:31: index escapes to heap:
.\txn.go:172:31: index escapes to heap:
.\txn.go:187:31: index escapes to heap:
.\txn.go:202:31: index escapes to heap:
*/
txn.rangeRead(func(offset uint32, index bitmap.Bitmap) {
c.Column.(Numeric).FilterFloat64(offset, index, predicate)
})
Expand Down Expand Up @@ -387,10 +381,6 @@ func (txn *Txn) rollback() {
txn.reset()
}

func (txn *Txn) release() {
txn.owner.txns.release(txn)
}

// Commit commits the transaction by applying all pending updates and deletes to
// the collection. This operation is can be called several times for a transaction
// in order to perform partial commits. If there's no pending updates/deletes, this
Expand Down Expand Up @@ -466,6 +456,7 @@ func (txn *Txn) commitUpdates(chunk, max uint32) (typ commit.Type) {
return
}

// commitBitmaps commits inserts and deletes bitmaps to the collection.
func (txn *Txn) commitBitmaps(chunk uint32, fill, deletes, inserts bitmap.Bitmap) (typ commit.Type) {
if len(inserts) > 0 {
typ |= commit.Insert
Expand All @@ -488,6 +479,5 @@ func (txn *Txn) commitBitmaps(chunk uint32, fill, deletes, inserts bitmap.Bitmap
fill.Or(inserts)
atomic.StoreUint64(&txn.owner.count, uint64(txn.owner.fill.Count()))
txn.owner.lock.Unlock()

return
}

0 comments on commit b1bb999

Please sign in to comment.