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

Catch2 tool: Convert range to value unit #240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
29 changes: 28 additions & 1 deletion src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,33 @@ function extractGoogleCppResult(output: string): BenchmarkResult[] {
});
}


function convertTime(value: number, fromUnit: string, toUnit: string): number {
if (fromUnit === toUnit) {
return value;
}
let milliValue = value;
switch (fromUnit) {
case 'us':
milliValue = value * 1e-3;
break;
case 's':
milliValue = value * 1e3;
break;
default:
return milliValue;
}

switch (toUnit) {
case 'us':
return milliValue * 1e3;
case 's':
return milliValue * 1e-3;
default:
return milliValue;
}
}

function extractCatch2Result(output: string): BenchmarkResult[] {
// Example:

Expand Down Expand Up @@ -524,7 +551,7 @@ function extractCatch2Result(output: string): BenchmarkResult[] {
);
}

const range = '± ' + stdDev[1].trim();
const range = '± ' + convertTime(parseFloat(stdDev[1]), stdDev[2], unit);

// Skip empty line
const [emptyLine, emptyLineNum] = nextLine();
Expand Down