From f2c17682b0a6226360298ef51708ca38b0e561e4 Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Fri, 5 Apr 2024 22:37:39 -0700 Subject: [PATCH] x/model: add BenchmarkNameDisplay Also, use range over int in other benchmarks. --- x/model/name_test.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/x/model/name_test.go b/x/model/name_test.go index b44be44b1..47dfd9876 100644 --- a/x/model/name_test.go +++ b/x/model/name_test.go @@ -281,11 +281,22 @@ func TestParseNameAllocs(t *testing.T) { func BenchmarkParseName(b *testing.B) { b.ReportAllocs() - for i := 0; i < b.N; i++ { + for range b.N { keep(ParseName("example.com/mistral:7b+Q4_0")) } } +func BenchmarkNameDisplay(b *testing.B) { + b.ReportAllocs() + + r := ParseName("example.com/mistral:7b+Q4_0") + b.Run("Short", func(b *testing.B) { + for range b.N { + keep(r.DisplayShort()) + } + }) +} + func FuzzParseName(f *testing.F) { f.Add("example.com/mistral:7b+Q4_0") f.Add("example.com/mistral:7b+q4_0")