Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 0 additions & 70 deletions benchmark/complex.js

This file was deleted.

84 changes: 84 additions & 0 deletions benchmark/complex.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { baseCompile } from '@intlify/message-compiler'
import {
translate,
createCoreContext,
clearCompileCache
} from '@intlify/core-base'
import { createI18n } from 'vue-i18n'
import convertHrtime from 'convert-hrtime'
import { resolve, dirname } from 'pathe'
import { readJson } from './utils.mjs'

async function run() {
const data = await readJson(resolve(dirname('.'), './benchmark/complex.json'))
const len = Object.keys(data).length

console.log('complex pattern ...')

console.log(`compile time: ${len} resources`)
let start = convertHrtime(process.hrtime.bigint())
for (const [, source] of Object.entries(data)) {
baseCompile(source)
}
let end = convertHrtime(process.hrtime.bigint())
console.log(`ms: ${end.milliseconds - start.milliseconds}`)

console.log()

console.log(`resolve time with core: ${len} resources`)
const ctx = createCoreContext({
locale: 'en',
modifiers: {
caml: val => val
},
messages: {
en: data
}
})
start = convertHrtime(process.hrtime.bigint())
for (const [key] of Object.entries(data)) {
translate(ctx, key, 2)
}
end = convertHrtime(process.hrtime.bigint())
console.log(`sec: ${end.seconds - start.seconds}`)
console.log(`ms: ${end.milliseconds - start.milliseconds}`)

clearCompileCache()
console.log()

console.log(`resolve time on composition: ${len} resources`)
const i18n = createI18n({
legacy: false,
locale: 'en',
modifiers: {
caml: val => val
},
messages: {
en: data
}
})
start = convertHrtime(process.hrtime.bigint())
for (const [key] of Object.entries(data)) {
i18n.global.t(key, 2)
}
end = convertHrtime(process.hrtime.bigint())
console.log(`ms: ${end.milliseconds - start.milliseconds}`)

console.log(
`resolve time on composition with compile cache: ${len} resources`
)
start = convertHrtime(process.hrtime.bigint())
for (const [key] of Object.entries(data)) {
i18n.global.t(key, 2)
}
end = convertHrtime(process.hrtime.bigint())
console.log(`ms: ${end.milliseconds - start.milliseconds}`)
}

;(async () => {
try {
await run()
} catch (e) {
console.error(e)
}
})()
29 changes: 0 additions & 29 deletions benchmark/index.js

This file was deleted.

31 changes: 31 additions & 0 deletions benchmark/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { exec } from 'child_process'
import { dirname } from 'pathe'

function run(pattner) {
return new Promise((resolve, reject) => {
exec(
`node ./benchmark/${pattner}.mjs`,
{ cwd: dirname('.') },
(error, stdout) => {
if (error) {
return reject(error)
}
console.log(stdout)
resolve()
}
)
})
}

;(async () => {
try {
for (const p of ['simple', 'complex']) {
await run(p)
}
// await asyncForEach(['simple', 'complex'], async p => {
// await run(p)
// })
} catch (e) {
console.error(e)
}
})()
64 changes: 0 additions & 64 deletions benchmark/simple.js

This file was deleted.

80 changes: 80 additions & 0 deletions benchmark/simple.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { baseCompile } from '@intlify/message-compiler'
import {
translate,
createCoreContext,
clearCompileCache
} from '@intlify/core-base'
import { createI18n } from 'vue-i18n'
import convertHrtime from 'convert-hrtime'
import { resolve, dirname } from 'pathe'
import { readJson } from './utils.mjs'

async function run() {
const simpleData = await readJson(
resolve(dirname('.'), './benchmark/simple.json')
)
const len = Object.keys(simpleData).length

console.log('simple pattern ...')

console.log(`compile time: ${len} resources`)
let start = convertHrtime(process.hrtime.bigint())
for (const [, source] of Object.entries(simpleData)) {
baseCompile(source)
}
let end = convertHrtime(process.hrtime.bigint())
console.log(`sec: ${end.seconds - start.seconds}`)
console.log(`ms: ${end.milliseconds - start.milliseconds}`)

console.log()

console.log(`resolve time with core: ${len} resources`)
const ctx = createCoreContext({
locale: 'en',
messages: {
en: simpleData
}
})
start = convertHrtime(process.hrtime.bigint())
for (const [key] of Object.entries(simpleData)) {
translate(ctx, key)
}
end = convertHrtime(process.hrtime.bigint())
console.log(`ms: ${end.milliseconds - start.milliseconds}`)

clearCompileCache()
console.log()

console.log(`resolve time on composition: ${len} resources`)
const i18n = createI18n({
legacy: false,
locale: 'en',
messages: {
en: simpleData
}
})
start = convertHrtime(process.hrtime.bigint())
for (const [key] of Object.entries(simpleData)) {
i18n.global.t(key)
}
end = convertHrtime(process.hrtime.bigint())
console.log(`ms: ${end.milliseconds - start.milliseconds}`)

console.log(
`resolve time on composition with compile cache: ${len} resources`
)
start = convertHrtime(process.hrtime.bigint())
for (const [key] of Object.entries(simpleData)) {
i18n.global.t(key)
}
end = convertHrtime(process.hrtime.bigint())
console.log(`ms: ${end.milliseconds - start.milliseconds}`)
}

;(async () => {
try {
await run()
} catch (e) {
console.error(e)
}
})()
7 changes: 7 additions & 0 deletions benchmark/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import fs from 'fs/promises'

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export async function readJson(path) {
const data = await fs.readFile(path, 'utf8')
return JSON.parse(data)
}
Loading