perf(decode): parse struct destinations without the value tree
Test / test (push) Successful in 1m50s
Test / test (push) Successful in 1m50s
Assisted-by: GLM 5.3 Flash
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
package interpres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -168,3 +169,39 @@ func BenchmarkMarshalLong(b *testing.B) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// BenchmarkStrictDecodeTree measures the reference path the targeted decode
|
||||
// is measured against: the full tree parse followed by the reflection walk.
|
||||
// The pair runs in one process, so the A/B comparison shares the machine.
|
||||
func BenchmarkStrictDecodeTree(b *testing.B) {
|
||||
dec := newDecoder()
|
||||
dec.disallowUnknown = true
|
||||
b.ReportAllocs()
|
||||
for b.Loop() {
|
||||
tree, _, err := parseWithOptions(context.Background(), benchDoc, parseOptions{}, false)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
var cfg benchConfig
|
||||
if err := dec.decode(tree, &cfg); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkStrictDecodeTreeLong(b *testing.B) {
|
||||
dec := newDecoder()
|
||||
dec.disallowUnknown = true
|
||||
b.ReportAllocs()
|
||||
b.SetBytes(int64(len(longDoc)))
|
||||
for b.Loop() {
|
||||
tree, _, err := parseWithOptions(context.Background(), longDoc, parseOptions{}, false)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
var doc benchLongDoc
|
||||
if err := dec.decode(tree, &doc); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user