Skip to content
Merged
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
11 changes: 9 additions & 2 deletions evaluation/leaderboard/aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,16 @@ export function aggregateScores(bundles: SignedResultBundle[]): LeaderboardEntry
benchmarkVersion: bundle.benchmarkVersion
}
};
}).sort((a, b) => b.score - a.score);
});

return aggregated.map((entry, index) => ({
const sorted = [...aggregated].sort((a, b) => {
if (a.score !== b.score) return b.score - a.score;
if (a.model < b.model) return -1;
if (a.model > b.model) return 1;
return 0;
});
Comment on lines +35 to +40
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The use of the spread operator [...aggregated] creates an unnecessary shallow copy of the aggregated array. Since aggregated is a new array returned from the .map() operation and is not used again after this sort, you can sort it in-place to improve performance and simplify the code.

Suggested change
const sorted = [...aggregated].sort((a, b) => {
if (a.score !== b.score) return b.score - a.score;
if (a.model < b.model) return -1;
if (a.model > b.model) return 1;
return 0;
});
const sorted = aggregated.sort((a, b) => {
if (a.score !== b.score) return b.score - a.score;
if (a.model < b.model) return -1;
if (a.model > b.model) return 1;
return 0;
});


return sorted.map((entry, index) => ({
...entry,
rank: index + 1
}));
Expand Down
Loading