Skip to content

Commit 91f725c

Browse files
committed
feat: formatting for Memory used improvement
1 parent 7956c00 commit 91f725c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/compiler/executeCommandLine.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,12 +1266,31 @@ function statisticValue(s: Statistic) {
12661266
case StatisticType.time:
12671267
return (s.value / 1000).toFixed(2) + "s";
12681268
case StatisticType.memory:
1269-
return Math.round(s.value / 1000) + "K";
1269+
return formatMemory(s.value);
12701270
default:
12711271
Debug.assertNever(s.type);
12721272
}
12731273
}
12741274

1275+
function formatMemory(bytes: number) {
1276+
// bytes -> choose KB/MB/GB with a human friendly format
1277+
const KB = 1024;
1278+
const MB = KB * 1024;
1279+
const GB = MB * 1024;
1280+
const numberOfDigitsAfterTheDecimalPoint = 1;
1281+
1282+
if (bytes >= GB) {
1283+
return (bytes / GB).toFixed(numberOfDigitsAfterTheDecimalPoint) + " GB";
1284+
}
1285+
1286+
if (bytes >= MB) {
1287+
return (bytes / MB).toFixed(numberOfDigitsAfterTheDecimalPoint) + " MB";
1288+
}
1289+
1290+
const kilobytesUsed = Math.round(bytes / KB);
1291+
return kilobytesUsed + " KB";
1292+
}
1293+
12751294
function writeConfigFile(
12761295
sys: System,
12771296
reportDiagnostic: DiagnosticReporter,

0 commit comments

Comments
 (0)