diff --git a/src/write.ts b/src/write.ts index 27e13798e..d9344f28a 100644 --- a/src/write.ts +++ b/src/write.ts @@ -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 ?? ''; @@ -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); 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 }