43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package engine
|
|
|
|
import (
|
|
"strconv"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/ConfigKit/internal/document"
|
|
)
|
|
|
|
func BenchmarkSequenceMixedUpsert(b *testing.B) {
|
|
for _, size := range []int{128, 512, 2048} {
|
|
b.Run(strconv.Itoa(size), func(b *testing.B) {
|
|
lower := benchmarkSequenceRecords(0, size, "lower")
|
|
higher := benchmarkSequenceRecords(size/2, size, "higher")
|
|
context := sequenceCombinationContext{destination: Keys("items")}
|
|
identityFields := []string{"id"}
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for range b.N {
|
|
if _, diagnostics := combineIdentifiedSequences(
|
|
lower, higher, sequenceModeUpsert, identityFields, context,
|
|
); len(diagnostics) != 0 {
|
|
b.Fatal(diagnostics)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func benchmarkSequenceRecords(start, count int, value string) *document.Node {
|
|
items := make([]*document.Node, count)
|
|
for index := range count {
|
|
items[index] = &document.Node{
|
|
Kind: document.Mapping,
|
|
Mapping: []document.Entry{
|
|
{Key: "id", Value: &document.Node{Kind: document.String, Text: "item-" + strconv.Itoa(start+index)}},
|
|
{Key: "value", Value: &document.Node{Kind: document.String, Text: value}},
|
|
},
|
|
}
|
|
}
|
|
return &document.Node{Kind: document.Sequence, Sequence: items}
|
|
}
|