From 5ad69f7a4f545368ab59302b18fa63bbff83f4d5 Mon Sep 17 00:00:00 2001 From: wwerkk Date: Thu, 18 Apr 2024 18:39:47 +0200 Subject: [PATCH] accordingly convert range to unit of mean bench measurement --- src/extract.ts | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/extract.ts b/src/extract.ts index 1bfb47ac2..f34d92769 100644 --- a/src/extract.ts +++ b/src/extract.ts @@ -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: @@ -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();