-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_bench_test.go
More file actions
132 lines (114 loc) · 3.4 KB
/
Copy pathdata_bench_test.go
File metadata and controls
132 lines (114 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// SPDX-License-Identifier: EUPL-1.2
// Benchmarks for the Data primitive in data.go.
// Per AX-11 — Data is the embedded-asset registry every agent persona,
// every prompt template, every CLI banner loads from. Read hot path is
// ReadString — agent boot reads dozens; chat-turn fast-path reads one.
// The bench gates the resolve→read pipeline.
//
// Run: go test -bench='BenchmarkData' -benchmem -run='^$' .
package core_test
import (
"testing/fstest"
. "dappco.re/go"
)
// Sinks defeat compiler DCE.
var (
dataSinkResult Result
dataSinkStrings []string
)
// dataFixture mounts a small in-memory FS as a Data entry.
// Mirrors how consumer packages declare their embedded.FS at boot.
func dataFixture() *Core {
c := New()
fsys := fstest.MapFS{
"prompts/coding.md": &fstest.MapFile{Data: []byte("# Coding\n\n```go\nfunc main() {}\n```\n")},
"prompts/review.md": &fstest.MapFile{Data: []byte("# Review checklist\n- correctness\n- tests\n- docs\n")},
"prompts/triage.md": &fstest.MapFile{Data: []byte("# Triage\n\nSurface the smallest reproducer.\n")},
"flow/deploy/homelab.yaml": &fstest.MapFile{Data: []byte("target: homelab\nbranch: dev\n")},
"flow/deploy/de1.yaml": &fstest.MapFile{Data: []byte("target: de1\nbranch: main\n")},
"persona/code/cladius.md": &fstest.MapFile{Data: []byte("persona: cladius\n")},
"persona/code/hephaestus.md": &fstest.MapFile{Data: []byte("persona: hephaestus\n")},
}
c.Data().New(NewOptions(
Option{Key: "name", Value: "brain"},
Option{Key: "source", Value: FS(fsys)},
Option{Key: "path", Value: "."},
))
return c
}
// --- Read paths ---
func BenchmarkData_ReadFile_Hit(b *B) {
c := dataFixture()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
dataSinkResult = c.Data().ReadFile("brain/prompts/coding.md")
}
}
func BenchmarkData_ReadFile_Miss(b *B) {
c := dataFixture()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
dataSinkResult = c.Data().ReadFile("brain/noexist.md")
}
}
func BenchmarkData_ReadString_Hit(b *B) {
c := dataFixture()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
dataSinkResult = c.Data().ReadString("brain/prompts/coding.md")
}
}
// --- List paths ---
func BenchmarkData_List(b *B) {
c := dataFixture()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
dataSinkResult = c.Data().List("brain/prompts")
}
}
func BenchmarkData_ListNames(b *B) {
c := dataFixture()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
dataSinkResult = c.Data().ListNames("brain/prompts")
}
}
// --- Mounts registry ---
func BenchmarkData_Mounts(b *B) {
c := dataFixture()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
dataSinkStrings = c.Data().Mounts()
}
}
// --- New (mount registration) ---
func BenchmarkData_New(b *B) {
fsys := fstest.MapFS{
"a.md": &fstest.MapFile{Data: []byte("a")},
}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
c := New()
dataSinkResult = c.Data().New(NewOptions(
Option{Key: "name", Value: "bench"},
Option{Key: "source", Value: FS(fsys)},
Option{Key: "path", Value: "."},
))
}
}
func BenchmarkData_Extract(b *B) {
fsys := fstest.MapFS{
"tmpl/a.md": &fstest.MapFile{Data: []byte("content")},
}
c := New()
c.Data().New(NewOptions(
Option{Key: "name", Value: "bench"},
Option{Key: "source", Value: FS(fsys)},
Option{Key: "path", Value: "."},
))
base := b.TempDir()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
dataSinkResult = c.Data().Extract("tmpl", PathJoin(base, Itoa(i)), nil)
}
}