Skip to content

Commit

Permalink
Make data set render (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
smarr authored Jul 18, 2023
2 parents 892f59c + aaa70a0 commit 507c99b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/backend/compare/html/stats-row-across-exes.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
itOut = new h.PerIterationOutput('', '<br>');
for (const e of it.exes) {
%}{%- itOut.next()
%}{%= medianFmtFn(e.criteria[i].median) %}
%}{%= (!e.criteria[i]) ? '' : medianFmtFn(e.criteria[i].median) %}
{% }
%}</span></td>
<td>
{%
itOut = new h.PerIterationOutput('', '<br>');
for (const e of it.exes) {
%}{%- itOut.next()
%}<span class="stats-change{%= cssClassForTotal %}" title="diff %">{%= changeFmtFn(e.criteria[i].change_m) %}</span>
%}<span class="stats-change{%= cssClassForTotal %}" title="diff %">{%= (!e.criteria[i]) ? '' : changeFmtFn(e.criteria[i].change_m) %}</span>
{% }
%}</td>{%
} %}
6 changes: 4 additions & 2 deletions src/backend/compare/html/stats-row-across-versions.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
{% for (const i of it.criteriaOrder) {
const cssClassForTotal = i === 'total' ? ' stats-total' : '';
let median;
if (i === 'total') {
if (!s[i]) {
median = '';
} else if (i === 'total') {
median = f.r2(s[i].median);
} else {
switch (it.criteria[i].unit) {
Expand All @@ -19,7 +21,7 @@
}
}

const change = f.per(s[i].change_m);
const change = (!s[i]) ? '' : f.per(s[i].change_m);
%}
<td><span class="stats-median" title="median">{%= median %}</span></td>
<td><span class="stats-change{%= cssClassForTotal %}" title="diff %">{%= change %}</span></td>{%
Expand Down
24 changes: 11 additions & 13 deletions src/backend/compare/prep-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -796,14 +796,8 @@ export async function calculateAcrossExesStatsForBenchmark(
const exes = new Set<string>();
for (const result of results) {
exes.add(result.exe);

// make sure we have the expected structure
assertBasicPropertiesOfSortedMeasurements(result, 0, 1);
assert(
result.measurements.length === results[0].measurements.length,
'For the rest of this code to work, ' +
'we assume that all results have the same shape, i.e., set of criteria.'
);
}

const exesArr = [...exes];
Expand All @@ -822,13 +816,17 @@ export async function calculateAcrossExesStatsForBenchmark(
const values: number[][] = [];

for (const result of results) {
assert(
result.measurements[i + changeOffset].criterion.name === criterion,
'We expect the same criteria to be at the same index'
);
const sorted = result.measurements[i + changeOffset].values.flat();
sorted.sort((a, b) => a - b);
values.push(sorted);
if (
result.measurements &&
result.measurements[i + changeOffset] &&
result.measurements[i + changeOffset].criterion.name === criterion
) {
const sorted = result.measurements[i + changeOffset].values.flat();
sorted.sort((a, b) => a - b);
values.push(sorted);
} else {
values.push([0]);
}
}

const stats = calculateChangeStatisticsForFirstAsBaseline(values);
Expand Down
6 changes: 0 additions & 6 deletions src/shared/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,6 @@ export function calculateChangeStatisticsForFirstAsBaseline(
sorted: number[][]
): ComparisonStatistics[] {
for (const series of sorted) {
if (series.length !== sorted[0].length) {
throw new Error(
`All arrays must have the same length, but ` +
`base has ${sorted[0].length}, while another has ${series.length}.`
);
}
if (!isSorted(series)) {
throw new Error('Input arrays must be sorted.');
}
Expand Down
23 changes: 13 additions & 10 deletions tests/shared/stats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,16 +355,19 @@ describe('calculateChangeStatisticsForFirstAsBaseline()', () => {
expect(stats[1].change_m).toEqual(0);
});

it('should given an error when base and change have different length', () => {
expect(() => {
calculateChangeStatisticsForFirstAsBaseline([
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
]);
}).toThrow(
`All arrays must have the same length, ` +
`but base has 10, while another has 11.`
);
it('should give results when base and change have different length', () => {
const stats = calculateChangeStatisticsForFirstAsBaseline([
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
]);

expect(stats[0].samples).toEqual(10);
expect(stats[0].median).toEqual(4.5);
expect(stats[0].change_m).toEqual(0);

expect(stats[1].samples).toEqual(11);
expect(stats[1].median).toEqual(5);
expect(stats[1].change_m).toEqual(0.11111111111111116);
});

it('should error on unordered data', () => {
Expand Down

0 comments on commit 507c99b

Please sign in to comment.