Skip to content

Commit 1d2fdb9

Browse files
authored
chore: sort by time (#59)
1 parent db2d33b commit 1d2fdb9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

scripts/src/compare.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import axios from 'axios';
22
import { readJson } from 'fs-extra';
3-
import { Metrics } from './shared/types';
43
import { DefaultBenchCase, getCommitLink, getMetricsPath } from './shared';
54

65
const productName = process.argv[2] || 'MODERNJS_FRAMEWORK';
@@ -77,13 +76,20 @@ export async function compare(productName: string) {
7776
process.argv[3] ||
7877
DefaultBenchCase[productName as keyof typeof DefaultBenchCase];
7978
const { jsonPath, remoteURL } = await getMetricsPath(productName, caseName);
80-
const allMetrics: Metrics[] =
79+
80+
const allMetrics =
8181
process.env.MONITOR === '1'
8282
? (await axios.get(remoteURL)).data
8383
: await readJson(jsonPath);
84-
const keys = Object.keys(allMetrics);
85-
const currentKey = keys[keys.length - 1];
86-
const baseKey = keys[keys.length - 2];
84+
85+
let arr = Object.keys(allMetrics).map(key => {
86+
return { key: key, value: allMetrics[key] };
87+
});
88+
89+
arr.sort((a, b) => a.value.time - b.value.time);
90+
91+
const currentKey = arr[arr.length - 1].key;
92+
const baseKey = arr[arr.length - 2].key;
8793
const current = allMetrics[currentKey as any];
8894
const base = allMetrics[baseKey as any];
8995
const baseCommitLink = getCommitLink(productName, baseKey);

0 commit comments

Comments
 (0)