Skip to content

Commit bc6455e

Browse files
committed
show increase as ratio too
1 parent 25d5ee2 commit bc6455e

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

packages/replay/metrics/src/results/analyzer.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export interface AnalyzerItemValue {
6868
readonly a: string;
6969
readonly b: string;
7070
readonly diff: string;
71+
readonly percent: string;
7172
}
7273

7374
class AnalyzerItemNumberValue implements AnalyzerItemValue {
@@ -87,6 +88,13 @@ class AnalyzerItemNumberValue implements AnalyzerItemValue {
8788
return diff > 0 ? `+${str}` : str;
8889
}
8990

91+
public get percent(): string {
92+
if (this._a == 0) return 'n/a';
93+
const diff = this._b / this._a * 100 - 100;
94+
const str = `${diff.toFixed(2)} %`;
95+
return diff > 0 ? `+${str}` : str;
96+
}
97+
9098
private _withUnit(value: number, isDiff: boolean = false): string {
9199
switch (this._unit) {
92100
case AnalyzerItemUnit.bytes:

packages/replay/metrics/src/results/pr-comment.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class PrCommentBuilder {
3737
${this._buffer}
3838
<hr />
3939
<div align="right">
40-
CPU usage difference is shown as <a href="https://en.wikipedia.org/wiki/Percentage_point">percentage points</a>. <br />
40+
*) pp - <a href="https://en.wikipedia.org/wiki/Percentage_point">percentage points</a> - an absolute difference between two percentages. <br />
4141
Last updated: <time datetime="${now.toISOString()}">${now.toUTCString()}</time>
4242
</div>
4343
`);
@@ -57,14 +57,14 @@ export class PrCommentBuilder {
5757
<table>
5858
<thead>`;
5959

60-
const headerCols = '<th align="right">Plain</th><th align="right">+Replay</th><th align="right">Diff</th>';
60+
const headerCols = '<th align="right">Plain</th><th align="right">+Replay</th><th align="right">Diff</th><th align="right">Ratio</th>';
6161
if (analysis.otherHash != undefined) {
6262
// If "other" is defined, add an aditional row of headers.
6363
this._buffer += `
6464
<tr>
6565
<th rowspan="2">&nbsp;</th>
66-
<th colspan="3" align="center">This PR (${await Git.hash})</th>
67-
<th colspan="3" align="center">${otherName} (${analysis.otherHash})</a></th>
66+
<th colspan="4" align="center">This PR (${await Git.hash})</th>
67+
<th colspan="4" align="center">${otherName} (${analysis.otherHash})</a></th>
6868
</tr>
6969
<tr>
7070
${headerCols}
@@ -85,10 +85,12 @@ export class PrCommentBuilder {
8585
<td align="right">${item.value.a}</td>
8686
<td align="right">${item.value.b}</td>
8787
<td align="right"><strong>${item.value.diff}</strong></td>
88+
<td align="right"><strong>${item.value.percent}</strong></td>
8889
${maybeOther(() => `
8990
<td align="right">${item.other!.a}</td>
9091
<td align="right">${item.other!.b}</td>
91-
<td align="right"><strong>${item.other!.diff}</strong></td>`)}
92+
<td align="right"><strong>${item.other!.diff}</strong></td>
93+
<td align="right"><strong>${item.other!.percent}</strong></td>`)}
9294
</tr>`
9395
}
9496

0 commit comments

Comments
 (0)