bench: Fix number formatting due to locale difference (#2655)

This commit is contained in:
acheron 2023-10-10 13:16:09 +02:00 committed by GitHub
parent 267c4ceab7
commit 721eb7a3be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 9 deletions

View File

@ -1,6 +1,6 @@
/** Sync Markdown files in /bench based on the data from bench.json */
import { BenchData, BenchResult, Markdown } from "./utils";
import { BenchData, BenchResult, Markdown, formatNumber } from "./utils";
(async () => {
const bench = await BenchData.open();
@ -41,7 +41,7 @@ import { BenchData, BenchResult, Markdown } from "./utils";
// New key
changeText = "N/A";
} else {
const delta = (newValue - oldValue).toLocaleString();
const delta = formatNumber(newValue - oldValue);
const percentChange = ((newValue / oldValue - 1) * 100).toFixed(2);
if (+percentChange > 0) {
@ -51,10 +51,10 @@ import { BenchData, BenchResult, Markdown } from "./utils";
}
}
table.insert(name, newValue.toLocaleString(), changeText);
table.insert(name, formatNumber(newValue), changeText);
},
noChangeCb: ({ name, value }) => {
table.insert(name, value.toLocaleString(), +i === 0 ? "N/A" : "-");
table.insert(name, formatNumber(value), +i === 0 ? "N/A" : "-");
},
});

View File

@ -527,11 +527,6 @@ export const getVersionFromArgs = () => {
: (args[anchorVersionArgIndex + 1] as Version);
};
/** Run `anchor test` command. */
export const runAnchorTest = () => {
return spawn("anchor", ["test", "--skip-lint"]);
};
/** Spawn a blocking process. */
export const spawn = (
cmd: string,
@ -549,3 +544,9 @@ export const spawn = (
return result;
};
/** Run `anchor test` command. */
export const runAnchorTest = () => spawn("anchor", ["test", "--skip-lint"]);
/** Format number with `en-US` locale. */
export const formatNumber = (number: number) => number.toLocaleString("en-US");