mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Format Size
This commit is contained in:
parent
6d4b27aacb
commit
bea76aa682
2
.github/workflows/e2e.yml
vendored
2
.github/workflows/e2e.yml
vendored
@ -108,8 +108,6 @@ jobs:
|
||||
run: |
|
||||
pnpm run build:viz
|
||||
mv stats cypress/snapshots/stats/head
|
||||
ls -l cypress/snapshots/stats/base
|
||||
ls -l cypress/snapshots/stats/head
|
||||
{
|
||||
echo 'size_diff<<EOF'
|
||||
npx tsx scripts/size.ts
|
||||
|
@ -21,6 +21,25 @@ const readStats = async (path: string): Promise<Record<string, number>> => {
|
||||
return Object.fromEntries(sizes);
|
||||
};
|
||||
|
||||
const formatBytes = (bytes: number): string => {
|
||||
if (bytes == 0) {
|
||||
return '0 Bytes';
|
||||
}
|
||||
const base = 1024;
|
||||
const decimals = 2;
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(base));
|
||||
return parseFloat((bytes / Math.pow(base, i)).toFixed(decimals)) + ' ' + sizes[i];
|
||||
};
|
||||
|
||||
const formatSize = (bytes: number): string => {
|
||||
const formatted = formatBytes(bytes);
|
||||
if (formatted.includes('Bytes')) {
|
||||
return formatted;
|
||||
}
|
||||
return `${formatBytes(bytes)} (${bytes} Bytes)`;
|
||||
};
|
||||
|
||||
const percentageDifference = (oldValue: number, newValue: number): string => {
|
||||
const difference = Math.abs(newValue - oldValue);
|
||||
const avg = (newValue + oldValue) / 2;
|
||||
@ -40,9 +59,13 @@ const main = async () => {
|
||||
.map(([key, value]) => {
|
||||
const oldValue = oldStats[key];
|
||||
const delta = value - oldValue;
|
||||
return [key, oldValue, value, delta, percentageDifference(oldValue, value)].map((v) =>
|
||||
v.toString()
|
||||
);
|
||||
return [
|
||||
key,
|
||||
formatSize(oldValue),
|
||||
formatSize(value),
|
||||
formatSize(delta),
|
||||
percentageDifference(oldValue, value),
|
||||
].map((v) => v.toString());
|
||||
})
|
||||
.filter(([, , , delta]) => delta !== '0');
|
||||
if (diff.length === 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user