Skip to content

Commit bbe230d

Browse files
committed
💄
1 parent ae89923 commit bbe230d

2 files changed

Lines changed: 204 additions & 154 deletions

File tree

benchmarks/builder_test.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package benchmarks
22

3-
// Benchmarks focused on the builder pattern before migration to functional options.
3+
// Benchmarks for the OopsErrorBuilder API.
44
//
5-
// The core overhead: every builder method calls copy(), which clones 3 maps
6-
// (context, userData, tenantData) and 1 slice (tags). A chain of N methods
7-
// pays that cost N times, regardless of whether the error is ever read.
5+
// These benchmarks target the current implementation and are designed for
6+
// cross-commit comparisons (e.g. benchstat main...HEAD).
87
//
98
// Run:
10-
// go test -bench=. -benchmem -count=10 ./benchmarks/ | tee bench-builder.txt
9+
// go test -bench=. -benchmem -count=10 ./benchmarks/ | tee bench.txt
1110
//
12-
// Compare after refactoring:
13-
// benchstat bench-builder.txt bench-functional-options.txt
11+
// Compare two commits:
12+
// benchstat bench-before.txt bench-after.txt
1413

1514
import (
1615
"errors"
@@ -278,7 +277,7 @@ func BenchmarkBuilderVsStdlib(b *testing.B) {
278277
b.Run("stdlib/fmt.Errorf", func(b *testing.B) {
279278
b.ReportAllocs()
280279
for i := 0; i < b.N; i++ {
281-
_ = errors.New("wrapped: " + inner.Error())
280+
_ = fmt.Errorf("wrapped: %w", inner)
282281
}
283282
})
284283

@@ -391,10 +390,7 @@ func BenchmarkOopsErrorMemoryFootprint(b *testing.B) {
391390
var after runtime.MemStats
392391
runtime.ReadMemStats(&after)
393392

394-
liveTotal := int64(after.HeapInuse) - int64(before.HeapInuse)
395-
if liveTotal < 0 {
396-
liveTotal = 0
397-
}
393+
liveTotal := max(int64(after.HeapInuse)-int64(before.HeapInuse), 0)
398394
b.ReportMetric(float64(liveTotal), "live-B/total")
399395
b.ReportMetric(float64(liveTotal)/float64(count), "live-B/error")
400396

0 commit comments

Comments
 (0)