Skip to content

Commit

Permalink
chore: add memoery usage
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Apr 13, 2024
1 parent 69914ea commit dfd3663
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 6 deletions.
3 changes: 3 additions & 0 deletions benchmark/compile.mjs
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -23,6 +24,8 @@ async function main() {
console.log(String(event.target))
})
.run()

displayMemoryUsage()
}

main().catch(err => {
Expand Down
4 changes: 3 additions & 1 deletion benchmark/complex-jit-aot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -76,6 +76,8 @@ async function main() {
console.log(String(event.target))
})
.run()

displayMemoryUsage()
}

main().catch(err => {
Expand Down
4 changes: 3 additions & 1 deletion benchmark/complex-jit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -65,6 +65,8 @@ async function main() {
console.log(String(event.target))
})
.run()

displayMemoryUsage()
}

main().catch(err => {
Expand Down
4 changes: 3 additions & 1 deletion benchmark/complex.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -59,6 +59,8 @@ async function main() {
console.log(String(event.target))
})
.run()

displayMemoryUsage()
}

main().catch(err => {
Expand Down
4 changes: 3 additions & 1 deletion benchmark/simple-jit-aot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -69,6 +69,8 @@ async function main() {
console.log(String(event.target))
})
.run()

displayMemoryUsage()
}

main().catch(err => {
Expand Down
4 changes: 3 additions & 1 deletion benchmark/simple-jit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -58,6 +58,8 @@ async function main() {
console.log(String(event.target))
})
.run()

displayMemoryUsage()
}

main().catch(err => {
Expand Down
4 changes: 3 additions & 1 deletion benchmark/simple.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -52,6 +52,8 @@ async function main() {
console.log(String(event.target))
})
.run()

displayMemoryUsage()
}

main().catch(err => {
Expand Down
19 changes: 19 additions & 0 deletions benchmark/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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(', '))
}

0 comments on commit dfd3663

Please sign in to comment.