From dfd36637b155519ec8b2d1723f2b4bb94dc8e3cf Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Sat, 13 Apr 2024 19:48:10 +0900 Subject: [PATCH] chore: add memoery usage --- benchmark/compile.mjs | 3 +++ benchmark/complex-jit-aot.mjs | 4 +++- benchmark/complex-jit.mjs | 4 +++- benchmark/complex.mjs | 4 +++- benchmark/simple-jit-aot.mjs | 4 +++- benchmark/simple-jit.mjs | 4 +++- benchmark/simple.mjs | 4 +++- benchmark/utils.mjs | 19 +++++++++++++++++++ 8 files changed, 40 insertions(+), 6 deletions(-) diff --git a/benchmark/compile.mjs b/benchmark/compile.mjs index 0e5531266..2a2c7b6dc 100644 --- a/benchmark/compile.mjs +++ b/benchmark/compile.mjs @@ -1,5 +1,6 @@ import { createCommonJS } from 'mlly' import { baseCompile } from '@intlify/message-compiler' +import { displayMemoryUsage } from './utils.mjs' const { require } = createCommonJS(import.meta.url) const { Suite } = require('benchmark') @@ -23,6 +24,8 @@ async function main() { console.log(String(event.target)) }) .run() + + displayMemoryUsage() } main().catch(err => { diff --git a/benchmark/complex-jit-aot.mjs b/benchmark/complex-jit-aot.mjs index 96deaaffc..b5982c142 100644 --- a/benchmark/complex-jit-aot.mjs +++ b/benchmark/complex-jit-aot.mjs @@ -11,7 +11,7 @@ import { } from '@intlify/core-base' import { createI18n } from 'vue-i18n' import { resolve, dirname } from 'pathe' -import { readJson } from './utils.mjs' +import { readJson, displayMemoryUsage } from './utils.mjs' const { require } = createCommonJS(import.meta.url) const { Suite } = require('benchmark') @@ -76,6 +76,8 @@ async function main() { console.log(String(event.target)) }) .run() + + displayMemoryUsage() } main().catch(err => { diff --git a/benchmark/complex-jit.mjs b/benchmark/complex-jit.mjs index 798579267..83c4bd3ca 100644 --- a/benchmark/complex-jit.mjs +++ b/benchmark/complex-jit.mjs @@ -10,7 +10,7 @@ import { } from '@intlify/core-base' import { createI18n } from 'vue-i18n' import { resolve, dirname } from 'pathe' -import { readJson } from './utils.mjs' +import { readJson, displayMemoryUsage } from './utils.mjs' const { require } = createCommonJS(import.meta.url) const { Suite } = require('benchmark') @@ -65,6 +65,8 @@ async function main() { console.log(String(event.target)) }) .run() + + displayMemoryUsage() } main().catch(err => { diff --git a/benchmark/complex.mjs b/benchmark/complex.mjs index 16583efb6..29839dd89 100644 --- a/benchmark/complex.mjs +++ b/benchmark/complex.mjs @@ -6,7 +6,7 @@ import { } from '@intlify/core-base' import { createI18n } from 'vue-i18n' import { resolve, dirname } from 'pathe' -import { readJson } from './utils.mjs' +import { readJson, displayMemoryUsage } from './utils.mjs' const { require } = createCommonJS(import.meta.url) const { Suite } = require('benchmark') @@ -59,6 +59,8 @@ async function main() { console.log(String(event.target)) }) .run() + + displayMemoryUsage() } main().catch(err => { diff --git a/benchmark/simple-jit-aot.mjs b/benchmark/simple-jit-aot.mjs index fda2554b0..d55b06053 100644 --- a/benchmark/simple-jit-aot.mjs +++ b/benchmark/simple-jit-aot.mjs @@ -11,7 +11,7 @@ import { } from '@intlify/core-base' import { createI18n } from 'vue-i18n' import { resolve, dirname } from 'pathe' -import { readJson } from './utils.mjs' +import { readJson, displayMemoryUsage } from './utils.mjs' const { require } = createCommonJS(import.meta.url) const { Suite } = require('benchmark') @@ -69,6 +69,8 @@ async function main() { console.log(String(event.target)) }) .run() + + displayMemoryUsage() } main().catch(err => { diff --git a/benchmark/simple-jit.mjs b/benchmark/simple-jit.mjs index 93f9008ec..db5715efd 100644 --- a/benchmark/simple-jit.mjs +++ b/benchmark/simple-jit.mjs @@ -10,7 +10,7 @@ import { } from '@intlify/core-base' import { createI18n } from 'vue-i18n' import { resolve, dirname } from 'pathe' -import { readJson } from './utils.mjs' +import { readJson, displayMemoryUsage } from './utils.mjs' const { require } = createCommonJS(import.meta.url) const { Suite } = require('benchmark') @@ -58,6 +58,8 @@ async function main() { console.log(String(event.target)) }) .run() + + displayMemoryUsage() } main().catch(err => { diff --git a/benchmark/simple.mjs b/benchmark/simple.mjs index 231f60068..cefa96918 100644 --- a/benchmark/simple.mjs +++ b/benchmark/simple.mjs @@ -6,7 +6,7 @@ import { } from '@intlify/core-base' import { createI18n } from 'vue-i18n' import { resolve, dirname } from 'pathe' -import { readJson } from './utils.mjs' +import { readJson, displayMemoryUsage } from './utils.mjs' const { require } = createCommonJS(import.meta.url) const { Suite } = require('benchmark') @@ -52,6 +52,8 @@ async function main() { console.log(String(event.target)) }) .run() + + displayMemoryUsage() } main().catch(err => { diff --git a/benchmark/utils.mjs b/benchmark/utils.mjs index 0b17e5fc6..e3ea4f75f 100644 --- a/benchmark/utils.mjs +++ b/benchmark/utils.mjs @@ -5,3 +5,22 @@ export async function readJson(path) { const data = await fs.readFile(path, 'utf8') return JSON.parse(data) } + +const numberFormatter = new Intl.NumberFormat('en', { + maximumFractionDigits: 2, + minimumFractionDigits: 2 +}) + +function displaySize(bytes) { + return `${numberFormatter.format(bytes / 1000)} kB` +} + +export function displayMemoryUsage() { + const heap = process.memoryUsage() + const msg = [] + for (const key in heap) { + msg.push(`${key}: ${displaySize(heap[key])}`) + } + console.log() + console.log('memory usage:', msg.join(', ')) +}