Skip to content

Commit f5dbe13

Browse files
committed
get closer to original structure
1 parent ae1c338 commit f5dbe13

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/extract.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,6 @@ function extractCargoResult(output: string): BenchmarkResult[] {
344344
}
345345

346346
export function extractGoResult(output: string): BenchmarkResult[] {
347-
const benchmarkRegex =
348-
/^(?<name>Benchmark\w+[\w()$%^&*-=|,[\]{}"#]*?)(?<procs>-\d+)?\s+(?<times>\d+)\s+(?<remainder>.+)$/;
349-
350347
// Split into sections by "pkg:" lines, keeping package name with each section
351348
const sections = output.split(/^pkg:\s+/m).map((section, index) => {
352349
if (index === 0) return { pkg: '', lines: section.split(/\r?\n/g) };
@@ -356,10 +353,23 @@ export function extractGoResult(output: string): BenchmarkResult[] {
356353

357354
const hasMultiplePackages = sections.filter((s) => s.pkg).length > 1;
358355

356+
// Example:
357+
// BenchmarkFib20-8 30000 41653 ns/op
358+
// BenchmarkDoWithConfigurer1-8 30000000 42.3 ns/op
359+
360+
// Example if someone has used the ReportMetric function to add additional metrics to each benchmark:
361+
// BenchmarkThing-16 1 95258906556 ns/op 64.02 UnitsForMeasure2 31.13 UnitsForMeasure3
362+
363+
// reference, "Proposal: Go Benchmark Data Format": https://go.googlesource.com/proposal/+/master/design/14313-benchmark-format.md
364+
// "A benchmark result line has the general form: <name> <iterations> <value> <unit> [<value> <unit>...]"
365+
// "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."
366+
const reExtractRegexp =
367+
/^(?<name>Benchmark\w+[\w()$%^&*-=|,[\]{}"#]*?)(?<procs>-\d+)?\s+(?<times>\d+)\s+(?<remainder>.+)$/;
368+
359369
// Process each section and flatten results
360370
return sections.flatMap(({ pkg, lines }) =>
361371
lines.flatMap((line) => {
362-
const match = line.match(benchmarkRegex);
372+
const match = line.match(reExtractRegexp);
363373
if (!match?.groups) return [];
364374

365375
const { name, procs: procsRaw, times, remainder } = match.groups;

0 commit comments

Comments
 (0)