From 5fca7a69202ab80302111923dd5c8a9631d82289 Mon Sep 17 00:00:00 2001 From: Gabriel Vasile Date: Tue, 13 Aug 2024 01:54:58 +0900 Subject: [PATCH] add benchmark for csv detector allocs --- internal/magic/text_csv_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 internal/magic/text_csv_test.go diff --git a/internal/magic/text_csv_test.go b/internal/magic/text_csv_test.go new file mode 100644 index 00000000..a0ecad36 --- /dev/null +++ b/internal/magic/text_csv_test.go @@ -0,0 +1,20 @@ +package magic + +import ( + "io" + "math/rand" + "testing" +) + +func BenchmarkCsv(b *testing.B) { + r := rand.New(rand.NewSource(0)) + data := make([]byte, 4096) + if _, err := io.ReadFull(r, data); err != io.ErrUnexpectedEOF && err != nil { + b.Fatal(err) + } + + b.ReportAllocs() + for i := 0; i < b.N; i++ { + Csv(data, 0) + } +}