From 402477b200d1e0b9df54c02b182641ebda66e632 Mon Sep 17 00:00:00 2001 From: Jonas Knobloch Date: Tue, 14 Apr 2026 19:53:39 +0200 Subject: Add tensor allocation benchmarks --- gpt2/allocator_test.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 gpt2/allocator_test.go (limited to 'gpt2/allocator_test.go') diff --git a/gpt2/allocator_test.go b/gpt2/allocator_test.go new file mode 100644 index 0000000..4a7502c --- /dev/null +++ b/gpt2/allocator_test.go @@ -0,0 +1,52 @@ +package gpt2 + +import ( + "testing" + + ort "github.com/yalue/onnxruntime_go" +) + +const ( + batchSize = 1 + seqLen = 128 +) + +func BenchmarkStandard(b *testing.B) { + shape := ort.NewShape(batchSize, seqLen) + data := make([]int64, batchSize*seqLen) + + b.ResetTimer() + b.ReportAllocs() + + for i := 0; i < b.N; i++ { + t, err := ort.NewTensor(shape, data) + + if err != nil { + b.Fatal(err) + } + + t.Destroy() + } +} + +func BenchmarkPersistent(b *testing.B) { + shape := ort.NewShape(batchSize, seqLen) + data := make([]int64, batchSize*seqLen) + + persistent, err := ort.NewEmptyTensor[int64](shape) + + if err != nil { + b.Fatal(err) + } + + defer persistent.Destroy() + + buffer := persistent.GetData() + + b.ResetTimer() + b.ReportAllocs() + + for i := 0; i < b.N; i++ { + copy(buffer, data) + } +} -- cgit v1.3.1