From 4ea3e9efa6f3c6cd92cc5c2bb2f989ee25ff4e8f Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Wed, 3 Apr 2024 23:03:36 -0700 Subject: [PATCH] x/build/blob: lock in zero allocs for ParseRef --- x/build/blob/ref_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/x/build/blob/ref_test.go b/x/build/blob/ref_test.go index bf4333dfe..679af6f1d 100644 --- a/x/build/blob/ref_test.go +++ b/x/build/blob/ref_test.go @@ -78,3 +78,21 @@ func TestRefFull(t *testing.T) { }) } } + +func TestParseRefAllocs(t *testing.T) { + // test allocations + allocs := testing.AllocsPerRun(1000, func() { + ParseRef("example.com/mistral:7b+Q4_0") + }) + if allocs > 0 { + t.Errorf("ParseRef allocs = %v; want 0", allocs) + } +} + +func BenchmarkParseRef(b *testing.B) { + var r Ref + for i := 0; i < b.N; i++ { + r = ParseRef("example.com/mistral:7b+Q4_0") + } + _ = r +}