You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: include package name for duplicate bench names [#264] (#330)
## Problem Solved
When running Go benchmarks across multiple packages that have benchmarks
with the same name (e.g., `BenchmarkAppendMsgitem` in both
`middleware/cache` and `middleware/csrf`), the results would collide
since they shared identical names. This made it impossible to track them
separately over time.
## Solution
Benchmark names are now disambiguated by appending the package name in
parentheses when multiple packages are detected in the output:
- `BenchmarkFoo` → `BenchmarkFoo (github.com/example/package1)`
- `BenchmarkFoo` → `BenchmarkFoo (github.com/example/package2)`
**Backward compatible**: When only a single package exists (or no `pkg:`
lines), names remain unchanged.
## Code Changes
### `src/extract.ts` (+33/-28 lines)
- Refactored `extractGoResult()` to detect multiple packages by parsing
`pkg:` lines
- Split output into sections by package context
- Added `chunkPairs()` helper function for cleaner `[value, unit]` pair
extraction
- Changed from imperative loops to a functional, chained `flatMap`
approach
- Exported `extractGoResult` for direct unit testing
## New Test Coverage
### `test/extractGoResult.spec.ts` (254 lines)
Comprehensive unit tests covering:
- Basic benchmark extraction (with/without processor count)
- Multiple metrics per benchmark
- Single package backward compatibility
- Multiple package disambiguation (the main fix)
- Edge cases (orphan benchmarks, empty input, Windows line endings)
### Test fixtures added
- `go_fiber_duplicate_names_output.txt` - Real-world example with
duplicate names across `cache` and `csrf` packages
- `go_single_package_output.txt` - Single package output for backward
compatibility testing
@@ -356,15 +364,19 @@ function extractGoResult(output: string): BenchmarkResult[] {
356
364
// reference, "Proposal: Go Benchmark Data Format": https://go.googlesource.com/proposal/+/master/design/14313-benchmark-format.md
357
365
// "A benchmark result line has the general form: <name> <iterations> <value> <unit> [<value> <unit>...]"
358
366
// "The fields are separated by runs of space characters (as defined by unicode.IsSpace), so the line can be parsed with strings.Fields. The line must have an even number of fields, and at least four."
0 commit comments