-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitnet-benchmark-categories.mdc
More file actions
71 lines (55 loc) · 1.44 KB
/
bitnet-benchmark-categories.mdc
File metadata and controls
71 lines (55 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
description: "Define categories of benchmarks for the BitNet project to ensure focused and comparable measurements."
globs: pkg/bitnet/**/*.go
alwaysApply: false
---
# Benchmark Categories
**Purpose:** Classify benchmarks by their semantic focus so teams can compare like with like.
## 1. Creation Benchmarks
Measure cost of allocating or initializing a component.
```go
func BenchmarkTensor_Create(b *testing.B) {
for i := 0; i < b.N; i++ {
NewTensor(100)
}
}
```
## 2. Operation Benchmarks
Measure runtime of core operations on an existing instance.
```go
func BenchmarkTensor_Get(b *testing.B) {
tensor := NewTensor(1000)
b.ResetTimer()
for i := 0; i < b.N; i++ {
tensor.Get(i % 1000)
}
}
```
## 3. Composite / Sub-operation Benchmarks
Combine multiple operations or simulate realistic sequences.
```go
func BenchmarkTensor_Sequential(b *testing.B) {
tensor := NewTensor(1000)
b.Run("GetSet", func(b *testing.B) {
for i := 0; i < b.N; i++ {
tensor.Set(1.23, i%1000)
tensor.Get(i%1000)
}
})
}
```
## 4. Memory & Allocation Benchmarks
Measure allocations and memory footprint per operation.
```go
func BenchmarkAlloc_1024(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = make([]byte, 1024)
}
}
```
## Best Practices
* Single semantic focus per benchmark.
* Use realistic sizes and patterns.
* Report allocations with `b.ReportAllocs()`.
* Reset timers after setup (`b.ResetTimer()`).