Skip to content

Commit

Permalink
bench: Fix number formatting due to locale difference (#2655)
Browse files Browse the repository at this point in the history
  • Loading branch information
acheroncrypto authored Oct 10, 2023
1 parent 267c4ce commit 721eb7a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
8 changes: 4 additions & 4 deletions tests/bench/scripts/sync-markdown.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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" : "-");
},
});

Expand Down
11 changes: 6 additions & 5 deletions tests/bench/scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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");

1 comment on commit 721eb7a

@vercel
Copy link

@vercel vercel bot commented on 721eb7a Oct 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

anchor-docs – ./

www.anchor-lang.com
anchor-docs-200ms.vercel.app
anchor-docs-git-master-200ms.vercel.app
anchor-lang.com

Please sign in to comment.