From 548d5ace3f508628cc79701a6523ded0664d4259 Mon Sep 17 00:00:00 2001 From: wwerkk Date: Thu, 18 Apr 2024 18:17:51 +0200 Subject: [PATCH 1/3] getRatio: handle units by normalizing to milisecond --- src/write.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/write.ts b/src/write.ts index 27e13798e..87e3081b1 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 } From aac2041ba00d6b469cea10028e5bb13b2113858c Mon Sep 17 00:00:00 2001 From: wwerkk Date: Thu, 18 Apr 2024 18:24:16 +0200 Subject: [PATCH 2/3] fix linting --- src/write.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/write.ts b/src/write.ts index 87e3081b1..0ff7cfa33 100644 --- a/src/write.ts +++ b/src/write.ts @@ -159,11 +159,11 @@ function strVal(b: BenchmarkResult): string { function toMs(value: number, unit: string) { if (unit === undefined) return 0; switch (unit.toLowerCase()) { - case "us": + case 'us: return value / 1e3; - case "ms": + case 'ms': return value; - case "s": + case 's': return value * 1e3; default: return 0; From 9295c8a38edb7bcadb740938862177f079f5cf2a Mon Sep 17 00:00:00 2001 From: wwerkk <32481425+wwerkk@users.noreply.github.com> Date: Thu, 2 May 2024 15:49:24 +0200 Subject: [PATCH 3/3] fix typo src/write.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Chris TrzeĊ›niewski --- src/write.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/write.ts b/src/write.ts index 0ff7cfa33..d9344f28a 100644 --- a/src/write.ts +++ b/src/write.ts @@ -159,7 +159,7 @@ function strVal(b: BenchmarkResult): string { function toMs(value: number, unit: string) { if (unit === undefined) return 0; switch (unit.toLowerCase()) { - case 'us: + case 'us': return value / 1e3; case 'ms': return value;