Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #122: Alerts unit bug fix #239

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 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:
wwerkk marked this conversation as resolved.
Show resolved Hide resolved
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
}