test(bench): measure the long document on the typed decode and marshal paths
The suite gains BenchmarkStrictDecodeLong and BenchmarkMarshalLong over the same 2000-entry document ParseLong uses, so long-input work is visible on every path, not the parse alone. docs/BENCHMARKING.md lists them.
This commit is contained in:
@@ -127,3 +127,44 @@ func BenchmarkParseLong(b *testing.B) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// benchLongEntry mirrors one [[entry]] element of longDoc for the typed
|
||||||
|
// decode of the long document.
|
||||||
|
type benchLongEntry struct {
|
||||||
|
Name string `toml:"name"`
|
||||||
|
Weight int `toml:"weight"`
|
||||||
|
When time.Time `toml:"when"`
|
||||||
|
Ratio float64 `toml:"ratio"`
|
||||||
|
Tags []string `toml:"tags"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type benchLongDoc struct {
|
||||||
|
Title string `toml:"title"`
|
||||||
|
Entry []benchLongEntry `toml:"entry"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStrictDecodeLong(b *testing.B) {
|
||||||
|
dec := NewDecoder().DisallowUnknownFields()
|
||||||
|
b.ReportAllocs()
|
||||||
|
b.SetBytes(int64(len(longDoc)))
|
||||||
|
for b.Loop() {
|
||||||
|
var doc benchLongDoc
|
||||||
|
if err := dec.Decode(longDoc, &doc); err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkMarshalLong(b *testing.B) {
|
||||||
|
tree, err := ParseMap(longDoc)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
b.ReportAllocs()
|
||||||
|
b.SetBytes(int64(len(longDoc)))
|
||||||
|
for b.Loop() {
|
||||||
|
if _, err := Marshal(tree); err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,10 +9,12 @@ The benchmarks live in `bench_test.go`, next to the code they measure:
|
|||||||
|
|
||||||
| Benchmark | What it measures |
|
| Benchmark | What it measures |
|
||||||
|---|---|
|
|---|---|
|
||||||
| `BenchmarkParse` | `Parse` over a representative configuration document |
|
| `BenchmarkParse` | `ParseMap` over a representative configuration document |
|
||||||
| `BenchmarkMarshal` | `Marshal` of the tree `Parse` produced from the same document |
|
| `BenchmarkMarshal` | `Marshal` of the tree `ParseMap` produced from the same document |
|
||||||
| `BenchmarkStrictDecode` | `Decode` into a struct under `DisallowUnknownFields` |
|
| `BenchmarkStrictDecode` | `Decode` into a struct under `DisallowUnknownFields` |
|
||||||
| `BenchmarkParseLong` | `Parse` over a generated document with about 2000 array-of-tables entries |
|
| `BenchmarkParseLong` | `ParseMap` over a generated document with about 2000 array-of-tables entries |
|
||||||
|
| `BenchmarkStrictDecodeLong` | `Decode` into a typed document under `DisallowUnknownFields`, over the same long document |
|
||||||
|
| `BenchmarkMarshalLong` | `Marshal` of the tree `ParseMap` produced from the long document |
|
||||||
|
|
||||||
## Running
|
## Running
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user