Skip to content

Add summary table to compare page #1404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 17, 2022
Merged
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
47 changes: 8 additions & 39 deletions site/static/compare.html
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ <h2>Comparing <span id="stat-header">{{stat}}</span> between <span id="before">{
</span>
</span>
</div>
<input type="checkbox" v-model="filter.showNonRelevant" style="margin-left: 20px;" />
<input type="checkbox" v-model="filter.nonRelevant" style="margin-left: 20px;" />
</div>
<div class="section">
<div class="section-heading"><span>Display raw data</span>
Expand All @@ -274,53 +274,22 @@ <h2>Comparing <span id="stat-header">{{stat}}</span> between <span id="before">{
</div>
<input type="checkbox" v-model="showRawData" style="margin-left: 20px;" />
</div>
<button @click="resetFilter">Reset filters</button>
</div>
</fieldset>
<p v-if="dataLoading && !data">Loading ...</p>
<div v-if="data" id="content" style="margin-top: 15px">
<div id="summary">
<div style="display: flex; justify-content: end;">
<div id="main-summary">
<summary-table :cases="filteredSummary"></summary-table>
<div style="position: absolute; right: 5px; top: 5px;">
<span class="tooltip" style="margin-right: 1em;">?
<span class="tooltiptext">
The percents show arithmetic mean amongst regressions, amongst improvements
and finally amongst all benchmarks in each category (all benchmarks or
filtered benchmarks).
The table shows summaries of regressions, improvements and all changes
calculated from data that is currently visible (data that passes the
active filters).
</span>
</span>
</div>
<div v-for="summaryPair in Object.entries(summary)" class="summary-container">
<span style="font-weight: bold; margin-left: 5px; text-transform: capitalize;">{{
summaryPair[0] }}:</span>
<div class="summary-values">
<span class="summary summary-wide positive">
{{summaryPair[1].regressions.toString().padStart(3, "&nbsp;")}}
<svg style="width:18px;height:18px" viewBox="0 0 24 24">
<path
d="M16,6L18.29,8.29L13.41,13.17L9.41,9.17L2,16.59L3.41,18L9.41,12L13.41,16L19.71,9.71L22,12V6H16Z">
</path>
</svg>
&nbsp;(+{{(summaryPair[1].regressions_avg).toFixed(2)}}%)
</span>
<span class="summary">
{{summaryPair[1].unchanged.toString().padStart(3, "&nbsp;")}}
<svg style="width:18px;height:18px" viewBox="0 0 24 24">
<path d="M22,12L18,8V11H3V13H18V16L22,12Z"></path>
</svg>
</span>
<span class="summary summary-wide negative">
{{summaryPair[1].improvements.toString().padStart(3, "&nbsp;")}}
<svg style="width:18px;height:18px" viewBox="0 0 24 24">
<path
d="M16,18L18.29,15.71L13.41,10.83L9.41,14.83L2,7.41L3.41,6L9.41,12L13.41,8L19.71,14.29L22,12V18H16Z">
</path>
</svg>
&nbsp;({{(summaryPair[1].improvements_avg).toFixed(2)}}%)
</span>
<span class="summary" v-bind:class="percentClass(summaryPair[1].average)">
&nbsp;{{ signIfPositive(summaryPair[1].average) }}{{ (summaryPair[1].average).toFixed(2) }}%
</span>
</div>
</div>
</div>
<div v-if="data.new_errors.length">
<p><b>Newly broken benchmarks</b>:</p>
Expand Down
257 changes: 180 additions & 77 deletions site/static/compare/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@ function findQueryParam(name) {
}
}

function createDefaultFilter() {
return {
name: null,
nonRelevant: false,
profile: {
check: true,
debug: true,
opt: true,
doc: true
},
scenario: {
full: true,
incrFull: true,
incrUnchanged: true,
incrPatched: true
},
category: {
primary: true,
secondary: true
}
};
}

const app = Vue.createApp({
mounted() {
const app = this;
Expand All @@ -20,26 +43,7 @@ const app = Vue.createApp({
},
data() {
return {
filter: {
name: null,
showNonRelevant: false,
profile: {
check: true,
debug: true,
opt: true,
doc: true
},
scenario: {
full: true,
incrFull: true,
incrUnchanged: true,
incrPatched: true
},
category: {
primary: true,
secondary: true
}
},
filter: createDefaultFilter(),
showRawData: false,
data: null,
dataLoading: false
Expand Down Expand Up @@ -103,7 +107,7 @@ const app = Vue.createApp({
let nameFilter = filter.name && filter.name.trim();
nameFilter = !nameFilter || name.includes(nameFilter);

const relevanceFilter = filter.showNonRelevant ? true : testCase.isRelevant;
const relevanceFilter = filter.nonRelevant ? true : testCase.isRelevant;

return (
profileFilter(testCase.profile) &&
Expand Down Expand Up @@ -219,56 +223,9 @@ const app = Vue.createApp({
stat() {
return findQueryParam("stat") || "instructions:u";
},
summary() {
// Create object with each test case that is not filtered out as a key
const filtered = this.testCases.reduce((sum, next) => {
sum[testCaseString(next)] = true;
return sum;
}, {});
const newCount = {
regressions: 0,
regressions_avg: 0,
improvements: 0,
improvements_avg: 0,
unchanged: 0,
average: 0
};

const addDatum = (result, datum, percent) => {
if (percent > 0 && datum.is_relevant) {
result.regressions += 1;
result.regressions_avg += percent;
} else if (percent < 0 && datum.is_relevant) {
result.improvements += 1;
result.improvements_avg += percent;
} else {
result.unchanged += 1;
}
result.average += percent;
};

let result = {all: {...newCount}, filtered: {...newCount}}
for (let d of this.data.comparisons) {
const testCase = testCaseString(d)
const datumA = d.statistics[0];
const datumB = d.statistics[1];
let percent = 100 * ((datumB - datumA) / datumA);
addDatum(result.all, d, percent);
if (filtered[testCase]) {
addDatum(result.filtered, d, percent);
}
}

const computeAvg = (result) => {
result.improvements_avg /= Math.max(result.improvements, 1);
result.regressions_avg /= Math.max(result.regressions, 1);
result.average /= Math.max(result.regressions + result.improvements + result.unchanged, 1);
};
computeAvg(result.all);
computeAvg(result.filtered);

return result;

// Returns summary of currently filtered data
filteredSummary() {
return computeSummary(this.testCases);
},
benchmarkMap() {
if (!this.data) return {};
Expand All @@ -289,12 +246,6 @@ const app = Vue.createApp({
prLink(pr) {
return `https://github.com/rust-lang/rust/pull/${pr}`;
},
signIfPositive(pct) {
if (pct >= 0) {
return "+";
}
return "";
},
diffClass(diff) {
let klass = "";
if (diff > 1) {
Expand Down Expand Up @@ -331,6 +282,9 @@ const app = Vue.createApp({

return createUrlFromParams(createSearchParamsForMetric(metric, start, end));
},
resetFilter() {
this.filter = createDefaultFilter();
}
},
});

Expand Down Expand Up @@ -433,6 +387,86 @@ app.component('test-cases-table', {
</div>
`
});

const SummaryPercentValue = {
props: {
value: Number,
padWidth: {
type: Number,
default: null
}
},
template: `
<span><span v-html="padSpaces" />{{ formattedValue }}%</span>
`,
computed: {
formattedValue() {
return `${this.signIfPositive(this.value)}${this.value.toFixed(2)}`;
},
padSpaces() {
let value = this.formattedValue;
if (value.length < this.padWidth) {
return "&nbsp;".repeat(this.padWidth - value.length);
}
return "";
}
}
};
const SummaryRange = {
props: {
range: Array,
},
template: `
<div v-if="range.length > 0">
[<SummaryPercentValue :value="range[0]" :padWidth="6" />, <SummaryPercentValue :value="range[1]" :padWidth="6" />]
</div>
<div v-else>-</div>
`, components: {SummaryPercentValue}
};
const SummaryCount = {
props: {
cases: Number,
benchmarks: Number
},
template: `
<span :title="cases + ' test case(s), ' + benchmarks + ' unique benchmark(s)'">{{ cases }} ({{ benchmarks }})</span>
`
};

app.component('summary-table', {
props: ['cases'],
template: `
<table class="summary-table">
<thead>
<th><!-- icon --></th>
<th>Range</th>
<th>Mean</th>
<th>Count</th>
</thead>
<tbody>
<tr class="positive">
<td title="Regresions">❌</td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<td title="Regresions"></td>
<td title="Regressions"></td>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops :) Thanks. Will fix in #1410 if it gets merged, otherwise I'll send a separate PR.

<td><SummaryRange :range="cases.regressions.range" /></td>
<td><SummaryPercentValue :value="cases.regressions.average" /></td>
<td><SummaryCount :cases="cases.regressions.count" :benchmarks="cases.regressions.benchmarks" /></td>
</tr>
<tr class="negative">
<td title="Improvements">✅</td>
<td><SummaryRange :range="cases.improvements.range" /></td>
<td><SummaryPercentValue :value="cases.improvements.average" /></td>
<td><SummaryCount :cases="cases.improvements.count" :benchmarks="cases.improvements.benchmarks" /></td>
</tr>
<tr>
<td title="All changes">❌,✅</td>
<td><SummaryRange :range="cases.all.range" /></td>
<td><SummaryPercentValue :value="cases.all.average" /></td>
<td><SummaryCount :cases="cases.all.count" :benchmarks="cases.all.benchmarks" /></td>
</tr>
</tbody>
</table>
`,
components: {SummaryRange, SummaryPercentValue, SummaryCount}
});
app.mixin({
methods: {
percentClass(pct) {
Expand All @@ -448,6 +482,12 @@ app.mixin({
}
return klass;
},
signIfPositive(pct) {
if (pct >= 0) {
return "+";
}
return "";
},
}
});

Expand All @@ -470,6 +510,69 @@ function testCaseString(testCase) {
return testCase.benchmark + "-" + testCase.profile + "-" + testCase.scenario;
}

/**
* Computes summaries of improvements, regressions and all changes from the given `comparisons`.
* Returns a dictionary {improvements, regressions, all}.
*/
function computeSummary(testCases) {
const regressions = {
values: [],
benchmarks: new Set(),
};
const improvements = {
values: [],
benchmarks: new Set(),
};
const all = {
values: [],
benchmarks: new Set(),
};

const handleTestCase = (items, testCase) => {
items.benchmarks.add(testCase.benchmark);
items.values.push(testCase.percent);
};

for (const testCase of testCases) {
if (testCase.percent > 0) {
handleTestCase(regressions, testCase);
} else if (testCase.percent < 0) {
handleTestCase(improvements, testCase);
}
handleTestCase(all, testCase);
}

const computeSummary = (data) => {
const values = data.values;
const benchmarks = data.benchmarks;

const count = values.length;
let range = [];
if (count > 0) {
range = [
Math.min.apply(null, values),
Math.max.apply(null, values),
];
}

const sum = values.reduce((acc, item) => acc + item, 0);
const average = sum / Math.max(count, 1);

return {
count,
benchmarks: benchmarks.size,
average,
range,
}
};

return {
improvements: computeSummary(improvements),
regressions: computeSummary(regressions),
all: computeSummary(all)
};
}

function unique(arr) {
return arr.filter((value, idx) => arr.indexOf(value) == idx);
}
Expand Down
Loading