From 5a8f9bf36c10d7d08d8c6aefb37f30e4b7c483d4 Mon Sep 17 00:00:00 2001 From: blaine-arcjet <146491715+blaine-arcjet@users.noreply.github.com> Date: Mon, 13 May 2024 07:17:56 -0700 Subject: [PATCH 1/3] fix: Support sub-nanosecond precision on Cargo benchmarks --- src/extract.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extract.ts b/src/extract.ts index 1bfb47ac2..73879f945 100644 --- a/src/extract.ts +++ b/src/extract.ts @@ -315,7 +315,7 @@ function extractCargoResult(output: string): BenchmarkResult[] { const ret = []; // Example: // test bench_fib_20 ... bench: 37,174 ns/iter (+/- 7,527) - const reExtract = /^test (.+)\s+\.\.\. bench:\s+([0-9,]+) ns\/iter \(\+\/- ([0-9,]+)\)$/; + const reExtract = /^test (.+)\s+\.\.\. bench:\s+([0-9,.]+) ns\/iter \(\+\/- ([0-9,.]+)\)$/; const reComma = /,/g; for (const line of lines) { From 731956c4edd92244ec0b1d7b96e40ea2080bf597 Mon Sep 17 00:00:00 2001 From: Chris Trzesniewski Date: Sun, 19 May 2024 11:31:07 +0200 Subject: [PATCH 2/3] add tests and fix issue with parsing number as int instead of float --- src/extract.ts | 4 ++-- test/__snapshots__/extract.spec.ts.snap | 29 +++++++++++++++++++++++++ test/data/extract/cargo_output3.txt | 12 ++++++++++ test/extract.spec.ts | 4 ++++ 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 test/data/extract/cargo_output3.txt diff --git a/src/extract.ts b/src/extract.ts index 73879f945..a582e8907 100644 --- a/src/extract.ts +++ b/src/extract.ts @@ -314,7 +314,7 @@ function extractCargoResult(output: string): BenchmarkResult[] { const lines = output.split(/\r?\n/g); const ret = []; // Example: - // test bench_fib_20 ... bench: 37,174 ns/iter (+/- 7,527) + // test bench_fib_20 ... bench: 37,174.25 ns/iter (+/- 7,527.43) const reExtract = /^test (.+)\s+\.\.\. bench:\s+([0-9,.]+) ns\/iter \(\+\/- ([0-9,.]+)\)$/; const reComma = /,/g; @@ -325,7 +325,7 @@ function extractCargoResult(output: string): BenchmarkResult[] { } const name = m[1].trim(); - const value = parseInt(m[2].replace(reComma, ''), 10); + const value = parseFloat(m[2].replace(reComma, '')); const range = m[3].replace(reComma, ''); ret.push({ diff --git a/test/__snapshots__/extract.spec.ts.snap b/test/__snapshots__/extract.spec.ts.snap index d37f347a7..19f473cf9 100644 --- a/test/__snapshots__/extract.spec.ts.snap +++ b/test/__snapshots__/extract.spec.ts.snap @@ -175,6 +175,35 @@ exports[`extractResult() extracts benchmark output from cargo - cargo_output2.tx } `; +exports[`extractResult() extracts benchmark output from cargo - cargo_output3.txt 1`] = ` +{ + "benches": [ + { + "name": "bench_fib_10", + "range": "± 2.21", + "unit": "ns/iter", + "value": 148.7, + }, + { + "name": "bench_fib_20", + "range": "± 440.25", + "unit": "ns/iter", + "value": 18794.12, + }, + ], + "commit": { + "author": null, + "committer": null, + "id": "123456789abcdef", + "message": "this is dummy", + "timestamp": "dummy timestamp", + "url": "https://github.com/dummy/repo", + }, + "date": 1712131503296, + "tool": "cargo", +} +`; + exports[`extractResult() extracts benchmark output from cargo - criterion_output.txt 1`] = ` { "benches": [ diff --git a/test/data/extract/cargo_output3.txt b/test/data/extract/cargo_output3.txt new file mode 100644 index 000000000..631ec60b0 --- /dev/null +++ b/test/data/extract/cargo_output3.txt @@ -0,0 +1,12 @@ + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out + + +running 2 tests +test bench_fib_10 ... bench: 148.70 ns/iter (+/- 2.21) +test bench_fib_20 ... bench: 18,794.12 ns/iter (+/- 440.25) + +test result: ok. 0 passed; 0 failed; 0 ignored; 2 measured; 0 filtered out + diff --git a/test/extract.spec.ts b/test/extract.spec.ts index 2e8817e2b..b49567bec 100644 --- a/test/extract.spec.ts +++ b/test/extract.spec.ts @@ -67,6 +67,10 @@ describe('extractResult()', function () { tool: 'cargo', file: 'cargo_output2.txt', }, + { + tool: 'cargo', + file: 'cargo_output3.txt', + }, { tool: 'cargo', file: 'criterion_output.txt', From 90b96713742b1663cace37c5e67feea6a43e7ac8 Mon Sep 17 00:00:00 2001 From: Chris Trzesniewski Date: Sun, 19 May 2024 11:36:39 +0200 Subject: [PATCH 3/3] update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1d221a32..adbe0eded 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ ## Unreleased +- **fix** Support sub-nanosecond precision on Cargo benchmarks (#246) + # [v1.20.1](https://github.com/benchmark-action/github-action-benchmark/releases/tag/v1.20.1) - 02 Apr 2024