Skip to content
Closed
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
20 changes: 18 additions & 2 deletions src/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@ function strVal(b: BenchmarkResult): string {
return s;
}

function toMs(value: number, unit: string) {
if (unit === undefined) return 0;
switch (unit.toLowerCase()) {
case 'us':
return value / 1e3;
case 'ms':
return value;
case 's':
return value * 1e3;
default:
return 0;
}
}

function commentFooter(): string {
const repoMetadata = getCurrentRepoMetadata();
const repoUrl = repoMetadata.html_url ?? '';
Expand Down Expand Up @@ -566,8 +580,10 @@ async function handleSummary(benchName: string, currBench: Benchmark, prevBench:

function getRatio(tool: ToolType, prev: BenchmarkResult, current: BenchmarkResult) {
if (prev.value === 0 && current.value === 0) return 1;
const prevMs = toMs(prev.value, prev.unit);
const currentMs = toMs(current.value, current.unit);
Comment on lines +583 to +584
Copy link
Member

Choose a reason for hiding this comment

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

Not all benchmarks are output results in units of time and this logic will apply to all of them which would basically output 0 for all benchmarks that don't use us, ms or s as unit


return biggerIsBetter(tool)
? prev.value / current.value // e.g. current=100, prev=200
: current.value / prev.value; // e.g. current=200, prev=100
? prevMs / currentMs // e.g. current=100, prev=200
: currentMs / prevMs; // e.g. current=200, prev=100
}