From 644f3ed9d959decf2481d17f6b9745fba120e22e Mon Sep 17 00:00:00 2001 From: M Date: Sat, 29 Aug 2026 14:03:48 +0200 Subject: [PATCH] Benchmark what a bound draw costs --- bench_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/bench_test.go b/bench_test.go index 2c1ed5d..85c2665 100644 --- a/bench_test.go +++ b/bench_test.go @@ -57,6 +57,31 @@ func BenchmarkRepeat(b *testing.B) { benchPath(b, dir, "many") } +// BenchmarkBound measures a format that binds a head and reads two paths from it — +// what a correlated pair costs against BenchmarkUnbound, the same output drawn from +// two independent fields. +func BenchmarkBound(b *testing.B) { + dir := tmpData(b, "addr", `{"format":"{place.postal-code} {place.locality}","place":[ + {"format":"{locality}","locality":"Stockholm","postal-code":{"format":"#100 00"}}, + {"format":"{locality}","locality":"Tranås","postal-code":{"format":"#5#7#3 00"}}]}`) + benchPath(b, dir, "addr") +} + +func BenchmarkUnbound(b *testing.B) { + dir := tmpData(b, "addr", `{"format":"{postal-code} {locality}", + "postal-code":[{"format":"#100 00"},{"format":"#5#7#3 00"}], + "locality":["Stockholm","Tranås"]}`) + benchPath(b, dir, "addr") +} + +// BenchmarkBoundDeep reads two paths through an intermediate level, the shape the +// depth question is about. +func BenchmarkBoundDeep(b *testing.B) { + dir := tmpData(b, "addr", `{"format":"{p.addr.city} {p.addr.zip}","p":[ + {"format":"{addr}","addr":{"format":"{city}","city":["Stockholm","Tranås"],"zip":{"format":"#100 00"}}}]}`) + benchPath(b, dir, "addr") +} + // BenchmarkNew measures load+compile+validate of the whole shipped tree. func BenchmarkNew(b *testing.B) { b.ReportAllocs()