Jelajahi Sumber

x/model: add BenchmarkNameDisplay

Also, use range over int in other benchmarks.
Blake Mizerany 1 tahun lalu
induk
melakukan
f2c17682b0
1 mengubah file dengan 12 tambahan dan 1 penghapusan
  1. 12 1
      x/model/name_test.go

+ 12 - 1
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")