-
-
Notifications
You must be signed in to change notification settings - Fork 354
/
Copy pathsimple-jit-aot.mjs
64 lines (53 loc) · 1.42 KB
/
simple-jit-aot.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
global.__INTLIFY_JIT_COMPILATION__ = true // set JIT mode for Node.js
import {
clearCompileCache,
compile,
createCoreContext,
registerMessageCompiler,
translate
} from '@intlify/core-base'
import { baseCompile } from '@intlify/message-compiler'
import { bench, run } from 'mitata'
import { dirname, resolve } from 'node:path'
import { createI18n } from 'vue-i18n'
import { displayMemoryUsage, parseArgs, readJson } from './utils.mjs'
const args = parseArgs()
function precompile(data) {
const keys = Object.keys(data)
keys.forEach(key => {
const { ast } = baseCompile(data[key], { jit: true, location: false })
data[key] = ast
})
return data
}
const resources = await readJson(
resolve(dirname('.'), './benchmark/simple.json')
)
const len = Object.keys(resources).length
console.log(`simple pattern on ${len} resources (JIT + AOT):`)
registerMessageCompiler(compile)
const precompiledResources = precompile(resources)
const ctx = createCoreContext({
locale: 'en',
messages: {
en: precompiledResources
}
})
const i18n = createI18n({
locale: 'en',
messages: {
en: precompiledResources
}
})
bench(`resolve time with core`, () => {
translate(ctx, 'hello500')
})
bench(`resolve time on composition`, () => {
clearCompileCache()
i18n.global.t('hello500')
})
bench(`resolve time on composition with compile cache`, () => {
i18n.global.t('hello500')
})
await run(args)
displayMemoryUsage()