157 lines
4.6 KiB
Go
157 lines
4.6 KiB
Go
package engine
|
|
|
|
import (
|
|
"io"
|
|
"strconv"
|
|
"testing"
|
|
"testing/fstest"
|
|
)
|
|
|
|
type benchmarkCatalogConfig struct {
|
|
Catalog map[string]string `yaml:"catalog"`
|
|
}
|
|
|
|
type benchmarkNodeConfig struct {
|
|
Node string `yaml:"node"`
|
|
}
|
|
|
|
func BenchmarkUnderlayBroadCatalog(b *testing.B) {
|
|
for _, width := range []int{128, 256, 512} {
|
|
b.Run(strconv.Itoa(width), func(b *testing.B) {
|
|
inputs := make([]Input, 2)
|
|
for half := range inputs {
|
|
catalog := make(map[string]any, width/2)
|
|
for index := range width / 2 {
|
|
catalog["item-"+strconv.Itoa(half*width/2+index)] = "value"
|
|
}
|
|
inputs[half] = Input{Source: Mapping("catalog-"+strconv.Itoa(half), map[string]any{"catalog": catalog})}
|
|
}
|
|
options := LayeredOptions[benchmarkCatalogConfig]{Underlays: []Underlay{{Inputs: inputs}}}
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for range b.N {
|
|
if _, err := LoadLayered(Input{Source: NoSource()}, testSecretBinding(), options); err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func BenchmarkUnderlayManySmallTiers(b *testing.B) {
|
|
for _, count := range []int{32, 64, 128} {
|
|
b.Run(strconv.Itoa(count), func(b *testing.B) {
|
|
groups := make([]Underlay, count)
|
|
for index := range groups {
|
|
groups[index].Inputs = []Input{{Source: Mapping("item", map[string]any{
|
|
"catalog": map[string]any{"item-" + strconv.Itoa(index): "value"},
|
|
})}}
|
|
}
|
|
options := LayeredOptions[benchmarkCatalogConfig]{Underlays: groups}
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for range b.N {
|
|
if _, err := LoadLayered(Input{Source: NoSource()}, testSecretBinding(), options); err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func BenchmarkUnderlaySubtreeReplacement(b *testing.B) {
|
|
for _, count := range []int{32, 64, 128} {
|
|
b.Run(strconv.Itoa(count), func(b *testing.B) {
|
|
groups := make([]Underlay, count)
|
|
for index := range groups {
|
|
var node any = "temporary"
|
|
if index%2 == 0 {
|
|
node = map[string]any{"left": "one", "right": "two", "nested": map[string]any{"enabled": false}}
|
|
}
|
|
groups[index].Inputs = []Input{{Source: Mapping("replacement", map[string]any{"node": node})}}
|
|
}
|
|
options := LayeredOptions[benchmarkNodeConfig]{Underlays: groups}
|
|
main := Input{Source: Mapping("main", map[string]any{"node": "final"})}
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for range b.N {
|
|
if _, err := LoadLayered(main, testSecretBinding(), options); err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func BenchmarkUnderlayNativeImports(b *testing.B) {
|
|
for _, count := range []int{16, 32, 64} {
|
|
b.Run(strconv.Itoa(count), func(b *testing.B) {
|
|
files := fstest.MapFS{
|
|
"main.yml": &fstest.MapFile{Data: []byte("configkit: {imports: [{glob: 'defaults/*.yml'}]}\n")},
|
|
}
|
|
for index := range count {
|
|
name := "item-" + strconv.Itoa(index)
|
|
files["defaults/"+name+".yml"] = &fstest.MapFile{Data: []byte("catalog: {" + name + ": value}\n")}
|
|
}
|
|
filesystem := NewFilesystem("bundle", files)
|
|
main := Input{Source: filesystem.File("main.yml"), Imports: true}
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for range b.N {
|
|
if _, err := LoadLayered[benchmarkCatalogConfig](main, testSecretBinding()); err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func BenchmarkUnderlayRetainedHistory(b *testing.B) {
|
|
for _, count := range []int{16, 32, 64} {
|
|
b.Run(strconv.Itoa(count), func(b *testing.B) {
|
|
groups := make([]Underlay, count)
|
|
for index := range groups {
|
|
groups[index].Inputs = []Input{{Source: Mapping("value", map[string]any{
|
|
"catalog": map[string]any{"shared": strconv.Itoa(index)},
|
|
})}}
|
|
}
|
|
options := LayeredOptions[benchmarkCatalogConfig]{Underlays: groups}
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for range b.N {
|
|
result, err := LoadLayered(Input{Source: NoSource()}, testSecretBinding(), options)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
if _, ok := result.Inspection.Explain(Keys("catalog", "shared")); !ok {
|
|
b.Fatal("retained path was not explained")
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func BenchmarkUnderlayRenderedHistory(b *testing.B) {
|
|
for _, count := range []int{32, 64, 128} {
|
|
b.Run(strconv.Itoa(count), func(b *testing.B) {
|
|
groups := make([]Underlay, count)
|
|
for index := range groups {
|
|
groups[index].Inputs = []Input{{Source: Mapping("value", map[string]any{
|
|
"catalog": map[string]any{"shared": strconv.Itoa(index)},
|
|
})}}
|
|
}
|
|
result, err := LoadLayered(Input{Source: NoSource()}, testSecretBinding(), LayeredOptions[benchmarkCatalogConfig]{Underlays: groups})
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for range b.N {
|
|
if err := result.Inspection.WriteExplanation(io.Discard, Keys("catalog", "shared")); err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|