Skip to content

Commit

Permalink
Collect all statistics in a per-criterion map for easy processing
Browse files Browse the repository at this point in the history
  • Loading branch information
smarr committed Apr 28, 2023
1 parent a3c9ee2 commit 40ab798
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/stats-data-prep.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assert } from './logging.js';
import { calculateChangeStatistics } from './stats.js';
import { ComparisonStatistics, calculateChangeStatistics } from './stats.js';
import {
CriterionData,
MeasurementData,
Expand Down Expand Up @@ -207,7 +207,8 @@ export function dropMeasurementsWhereBaseOrChangeIsMissing(
export function calculateAllChangeStatistics(
measurements: Measurements[],
baseOffset: number,
changeOffset: number
changeOffset: number,
perCriteria: Map<string, ComparisonStatistics[]>
): Measurements[] | undefined {
assert(
measurements.length % 2 === 0,
Expand All @@ -231,9 +232,15 @@ export function calculateAllChangeStatistics(
const sortedChange = measurements[i + changeOffset].values.flat();
sortedChange.sort((a, b) => a - b);

measurements[i + changeOffset].changeStats = calculateChangeStatistics(
sortedBase,
sortedChange
);
const stats = calculateChangeStatistics(sortedBase, sortedChange);
measurements[i + changeOffset].changeStats = stats;

const criterionName = measurements[i + baseOffset].criterion.name;
let allStats = perCriteria.get(criterionName);
if (allStats === undefined) {
allStats = [];
perCriteria.set(criterionName, allStats);
}
allStats.push(stats);
}
}
13 changes: 12 additions & 1 deletion tests/stats-data-prep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
compareToSortForSinglePassChangeStats,
dropMeasurementsWhereBaseOrChangeIsMissing
} from '../src/stats-data-prep.js';
import { ComparisonStatistics } from '../src/stats.js';

describe('compareStringOrNull()', () => {
it('should compare null and null', () => {
Expand Down Expand Up @@ -460,6 +461,8 @@ describe('collateMeasurements()', () => {

describe('calculateAllChangeStatistics()', () => {
describe('with data from JsSOM', () => {
const perCriteria = new Map<string, ComparisonStatistics[]>();

const result: ResultsByExeSuiteBenchmark = collateMeasurements(
dataJsSOM.results
);
Expand All @@ -471,7 +474,8 @@ describe('calculateAllChangeStatistics()', () => {
const dropped = calculateAllChangeStatistics(
nbody.measurements,
0,
changeOffset
changeOffset,
perCriteria
);

it('should not have dropped any data', () => {
Expand All @@ -485,6 +489,13 @@ describe('calculateAllChangeStatistics()', () => {
expect(change.changeStats?.change_m).toBeCloseTo(-0.096325, 5);
expect(change.changeStats?.median).toBeCloseTo(81.384, 5);
expect(change.changeStats?.samples).toBe(10);
expect(perCriteria.size).toEqual(1);
expect(perCriteria.has('total')).toBe(true);

const total = <ComparisonStatistics[]>perCriteria.get('total');
expect(total).toHaveLength(1);

expect(total[0]).toBe(change.changeStats);
});
});
});

0 comments on commit 40ab798

Please sign in to comment.