From d7feffdeb3938a76437f4e6e0fafde3af1d0675d Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Fri, 5 May 2023 17:00:30 +0100 Subject: [PATCH] Put all the sorting related bits close to each other --- src/dashboard.ts | 12 ++++-------- src/stats-data-prep.ts | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/dashboard.ts b/src/dashboard.ts index a0d5f850..538b77b3 100644 --- a/src/dashboard.ts +++ b/src/dashboard.ts @@ -499,14 +499,10 @@ export async function calculateAllStatisticsAndRenderPlots( change: string, reportId: string ): Promise { - const cmp = base.localeCompare(change); - if (cmp === 0) { - throw new Error('base and change are the same'); - } - const baseCommitIdIsFirst = cmp < 0; - - const baseOffset = baseCommitIdIsFirst ? 0 : 1; - const changeOffset = baseCommitIdIsFirst ? 1 : 0; + const { baseOffset, changeOffset } = getCommitOffsetsInSortedMeasurements( + base, + change + ); const criteria = new Map(); diff --git a/src/stats-data-prep.ts b/src/stats-data-prep.ts index 6844e76a..93dc544a 100644 --- a/src/stats-data-prep.ts +++ b/src/stats-data-prep.ts @@ -75,6 +75,22 @@ export function compareToSortForSinglePassChangeStatsWithoutCommitId( return a.criterion.name.localeCompare(b.criterion.name); } +export function getCommitOffsetsInSortedMeasurements( + baseCommitId: string, + changeCommitId: string +): { baseOffset: number; changeOffset: number } { + const cmp = baseCommitId.localeCompare(changeCommitId); + if (cmp === 0) { + throw new Error('base and change are the same'); + } + const baseCommitIdIsFirst = cmp < 0; + + return { + baseOffset: baseCommitIdIsFirst ? 0 : 1, + changeOffset: baseCommitIdIsFirst ? 1 : 0 + }; +} + export interface ResultsByBenchmark { benchmarks: Map; criteria: Record;