mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 09:05:55 +00:00
Improvements and benchmarks for ingest field operation sorting
Reusing the field operation sorting for other things caused me to hit a bug, also made me curious about a performance issue and whether it was possible to improve it. Answer: Not easy to improve, anyway.
This commit is contained in:
parent
f2bc887d6f
commit
cff8da346f
2 changed files with 49 additions and 2 deletions
|
|
@ -243,8 +243,8 @@ func (f *FieldOperation) ByShard() ShardedFieldOperation {
|
|||
func (f *FieldOperation) clone() *FieldOperation {
|
||||
f2 := &FieldOperation{
|
||||
RecordIDs: append([]uint64{}, f.RecordIDs...),
|
||||
Values: append([]uint64{}, f.Values...),
|
||||
Signed: append([]int64{}, f.Signed...),
|
||||
Values: append(([]uint64)(nil), f.Values...),
|
||||
Signed: append(([]int64)(nil), f.Signed...),
|
||||
}
|
||||
return f2
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,53 @@
|
|||
|
||||
package ingest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
const sampleSize = 1000000
|
||||
|
||||
var sampleSortingData = createSampleFieldData()
|
||||
|
||||
func createSampleFieldData() *FieldOperation {
|
||||
fo := &FieldOperation{}
|
||||
fo.RecordIDs = make([]uint64, sampleSize)
|
||||
fo.Values = make([]uint64, sampleSize)
|
||||
fo.Signed = make([]int64, sampleSize)
|
||||
for i := range fo.RecordIDs {
|
||||
fo.RecordIDs[i] = (uint64(i) * 63 * 3456789) % 50000000
|
||||
fo.Values[i] = (uint64(i) * 6) % 8
|
||||
fo.Signed[i] = ((int64(i) * 17) % 15) - 8
|
||||
}
|
||||
return fo
|
||||
}
|
||||
|
||||
func benchmarkOneSort(b *testing.B, fo *FieldOperation) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.StopTimer()
|
||||
sortable := fo.clone()
|
||||
b.StartTimer()
|
||||
_ = sortable.SortToShards()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSortFieldOp(b *testing.B) {
|
||||
b.Run("full", func(b *testing.B) {
|
||||
f2 := *sampleSortingData
|
||||
benchmarkOneSort(b, &f2)
|
||||
})
|
||||
b.Run("nosign", func(b *testing.B) {
|
||||
f2 := *sampleSortingData
|
||||
f2.Signed = nil
|
||||
benchmarkOneSort(b, &f2)
|
||||
})
|
||||
b.Run("signonly", func(b *testing.B) {
|
||||
f2 := *sampleSortingData
|
||||
f2.Values = nil
|
||||
benchmarkOneSort(b, &f2)
|
||||
})
|
||||
}
|
||||
|
||||
// func BenchmarkSort64(b *testing.B) {
|
||||
// gen := func(n, width uint64) func() []uint64 {
|
||||
// var data []uint64
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue