Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions src/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,53 @@ function floatStr(n: number) {
return n.toString();
}

const round = (n: number, places = 3): number => parseFloat(n.toFixed(places));

function strDuration(n: number): string {
let unit = 'ns';
if (n >= 6e10) {
let secs = n / 1e9;
const mins = Math.floor(secs / 60);
secs %= 60;
return `${mins}m ${round(secs)}s`;
}

if (n >= 1e9) {
unit = 's';
n /= 1e9;
} else if (n >= 1e6) {
unit = 'ms';
n /= 1e6;
} else if (n >= 1e3) {
unit = 'μs';
n /= 1e3;
}

return `${round(n)}${unit}`;
}

const NS_RANGE_REGEX = /^±\s*([0-9]+)$/;

function strVal(b: BenchmarkResult): string {
let s = `\`${b.value}\` ${b.unit}`;
if (b.range) {
s += ` (\`${b.range}\`)`;
let s = '';
let range = b.range;

if (b.unit === 'ns/iter') {
s += `\`${strDuration(b.value)}/iter\``;
if (range?.match(NS_RANGE_REGEX)) {
range = '± ' + strDuration(parseInt(range.replace(NS_RANGE_REGEX, '$1')));
} else {
// If we can't show a unit, just give up...
range = undefined;
}
} else {
s += `\`${b.value} ${b.unit}\``;
}

if (range) {
s += `<br>(\`${range}\`)`;
}

return s;
}

Expand Down
12 changes: 6 additions & 6 deletions test/buildComment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ describe('buildComment', () => {

| Benchmark suite | Current: testCommitIdCurrent | Previous: testCommitIdPrevious | Ratio |
|-|-|-|-|
| \`TestBench<1>\` | \`0\` testUnit | \`0\` testUnit | \`1\` |
| \`TestBench<2>\` | \`1\` testUnit | \`0\` testUnit | \`+∞\` |
| \`TestBench<3>\` | \`-1\` testUnit | \`0\` testUnit | \`-∞\` |
| \`TestBench<1>\` | \`0 testUnit\` | \`0 testUnit\` | \`1\` |
| \`TestBench<2>\` | \`1 testUnit\` | \`0 testUnit\` | \`+∞\` |
| \`TestBench<3>\` | \`-1 testUnit\` | \`0 testUnit\` | \`-∞\` |

</details>

Expand Down Expand Up @@ -197,9 +197,9 @@ describe('buildComment', () => {

| Benchmark suite | Current: testCommitIdCurrent | Previous: testCommitIdPrevious | Ratio |
|-|-|-|-|
| \`TestBench<1>\` | \`0\` testUnit | \`0\` testUnit | \`1\` |
| \`TestBench<2>\` | \`0\` testUnit | \`1\` testUnit | \`+∞\` |
| \`TestBench<3>\` | \`0\` testUnit | \`-1\` testUnit | \`-∞\` |
| \`TestBench<1>\` | \`0 testUnit\` | \`0 testUnit\` | \`1\` |
| \`TestBench<2>\` | \`0 testUnit\` | \`1 testUnit\` | \`+∞\` |
| \`TestBench<3>\` | \`0 testUnit\` | \`-1 testUnit\` | \`-∞\` |

</details>

Expand Down
20 changes: 10 additions & 10 deletions test/write.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ describe.each(['https://github.com', 'https://github.enterprise.corp'])('writeBe
'',
'| Benchmark suite | Current: current commit id | Previous: prev commit id | Ratio |',
'|-|-|-|-|',
'| `bench_fib_10` | `210` ns/iter (`± 20`) | `100` ns/iter (`± 20`) | `2.10` |',
'| `bench_fib_20` | `25000` ns/iter (`± 20`) | `10000` ns/iter (`± 20`) | `2.50` |',
'| `bench_fib_10` | `210ns/iter`<br>(`± 20ns`) | `100ns/iter`<br>(`± 20ns`) | `2.10` |',
'| `bench_fib_20` | `25μs/iter`<br>(`± 20ns`) | `10μs/iter`<br>(`± 20ns`) | `2.50` |',
'',
`This comment was automatically generated by [workflow](${serverUrl}/user/repo/actions?query=workflow%3AWorkflow%20name) using [github-action-benchmark](https://github.com/marketplace/actions/continuous-benchmark).`,
'',
Expand Down Expand Up @@ -378,7 +378,7 @@ describe.each(['https://github.com', 'https://github.enterprise.corp'])('writeBe
'',
'| Benchmark suite | Current: current commit id | Previous: prev commit id | Ratio |',
'|-|-|-|-|',
'| `benchFib10` | `20` ops/sec (`+-20`) | `100` ops/sec (`+-20`) | `5` |',
'| `benchFib10` | `20 ops/sec`<br>(`+-20`) | `100 ops/sec`<br>(`+-20`) | `5` |',
'',
`This comment was automatically generated by [workflow](${serverUrl}/user/repo/actions?query=workflow%3AWorkflow%20name) using [github-action-benchmark](https://github.com/marketplace/actions/continuous-benchmark).`,
'',
Expand Down Expand Up @@ -416,7 +416,7 @@ describe.each(['https://github.com', 'https://github.enterprise.corp'])('writeBe
'',
'| Benchmark suite | Current: current commit id | Previous: prev commit id | Ratio |',
'|-|-|-|-|',
'| `bench_fib_10` | `210` ns/iter (`± 20`) | `100` ns/iter (`± 20`) | `2.10` |',
'| `bench_fib_10` | `210ns/iter`<br>(`± 20ns`) | `100ns/iter`<br>(`± 20ns`) | `2.10` |',
'',
`This comment was automatically generated by [workflow](${serverUrl}/user/repo/actions?query=workflow%3AWorkflow%20name) using [github-action-benchmark](https://github.com/marketplace/actions/continuous-benchmark).`,
'',
Expand Down Expand Up @@ -454,7 +454,7 @@ describe.each(['https://github.com', 'https://github.enterprise.corp'])('writeBe
'',
'| Benchmark suite | Current: current commit id | Previous: prev commit id | Ratio |',
'|-|-|-|-|',
'| `bench_fib_10` | `210` ns/iter (`± 20`) | `100` ns/iter (`± 20`) | `2.10` |',
'| `bench_fib_10` | `210ns/iter`<br>(`± 20ns`) | `100ns/iter`<br>(`± 20ns`) | `2.10` |',
'',
`This comment was automatically generated by [workflow](${serverUrl}/user/repo/actions?query=workflow%3AWorkflow%20name) using [github-action-benchmark](https://github.com/marketplace/actions/continuous-benchmark).`,
],
Expand Down Expand Up @@ -595,8 +595,8 @@ describe.each(['https://github.com', 'https://github.enterprise.corp'])('writeBe
'',
'| Benchmark suite | Current: current commit id | Previous: prev commit id | Ratio |',
'|-|-|-|-|',
'| `bench_fib_10` | `210` ns/iter (`± 20`) | `100` ns/iter (`± 20`) | `2.10` |',
'| `bench_fib_20` | `25000` ns/iter (`± 20`) | `10000` ns/iter (`± 20`) | `2.50` |',
'| `bench_fib_10` | `210ns/iter`<br>(`± 20ns`) | `100ns/iter`<br>(`± 20ns`) | `2.10` |',
'| `bench_fib_20` | `25μs/iter`<br>(`± 20ns`) | `10μs/iter`<br>(`± 20ns`) | `2.50` |',
'',
`This comment was automatically generated by [workflow](${serverUrl}/user/repo/actions?query=workflow%3AWorkflow%20name) using [github-action-benchmark](https://github.com/marketplace/actions/continuous-benchmark).`,
'',
Expand Down Expand Up @@ -634,7 +634,7 @@ describe.each(['https://github.com', 'https://github.enterprise.corp'])('writeBe
'',
'| Benchmark suite | Current: current commit id | Previous: prev commit id | Ratio |',
'|-|-|-|-|',
'| `benchFib10` | `100` ops/sec (`+-20`) | `100` ops/sec (`+-20`) | `1` |',
'| `benchFib10` | `100 ops/sec`<br>(`+-20`) | `100 ops/sec`<br>(`+-20`) | `1` |',
'',
`This comment was automatically generated by [workflow](${serverUrl}/user/repo/actions?query=workflow%3AWorkflow%20name) using [github-action-benchmark](https://github.com/marketplace/actions/continuous-benchmark).`,
'',
Expand Down Expand Up @@ -674,7 +674,7 @@ describe.each(['https://github.com', 'https://github.enterprise.corp'])('writeBe
'',
'| Benchmark suite | Current: current commit id | Previous: prev commit id | Ratio |',
'|-|-|-|-|',
'| `bench_fib_10` | `350` ns/iter (`± 20`) | `100` ns/iter (`± 20`) | `3.50` |',
'| `bench_fib_10` | `350ns/iter`<br>(`± 20ns`) | `100ns/iter`<br>(`± 20ns`) | `3.50` |',
'',
`This comment was automatically generated by [workflow](${serverUrl}/user/repo/actions?query=workflow%3AWorkflow%20name) using [github-action-benchmark](https://github.com/marketplace/actions/continuous-benchmark).`,
'',
Expand Down Expand Up @@ -1162,7 +1162,7 @@ describe.each(['https://github.com', 'https://github.enterprise.corp'])('writeBe
'',
'| Benchmark suite | Current: current commit id | Previous: prev commit id | Ratio |',
'|-|-|-|-|',
'| `bench_fib_10` | `210` ns/iter (`± 20`) | `100` ns/iter (`± 20`) | `2.10` |',
'| `bench_fib_10` | `210ns/iter`<br>(`± 20ns`) | `100ns/iter`<br>(`± 20ns`) | `2.10` |',
'',
`This comment was automatically generated by [workflow](${serverUrl}/user/repo/actions?query=workflow%3AWorkflow%20name) using [github-action-benchmark](https://github.com/marketplace/actions/continuous-benchmark).`,
],
Expand Down
Loading