Skip to content

Commit 790d279

Browse files
committed
chore: switch to mitata
1 parent 12aa95e commit 790d279

11 files changed

+323
-409
lines changed

benchmark/compile.mjs

+13-28
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,19 @@
11
import { baseCompile } from '@intlify/message-compiler'
2-
import { createCommonJS } from 'mlly'
3-
import { displayMemoryUsage } from './utils.mjs'
2+
import { bench, run } from 'mitata'
3+
import { displayMemoryUsage, parseArgs } from './utils.mjs'
44

5-
const { require } = createCommonJS(import.meta.url)
6-
const { Suite } = require('benchmark')
5+
const args = parseArgs()
6+
console.log(`compilation:`)
77

8-
async function main() {
9-
console.log(`compilation:`)
10-
console.log()
8+
bench(`compile simple message`, () => {
9+
baseCompile(`hello world`)
10+
})
1111

12-
new Suite('compilation')
13-
.add(`compile simple message`, () => {
14-
baseCompile(`hello world`)
15-
})
16-
.add(`compile complex message`, () => {
17-
// eslint-disable-next-line no-irregular-whitespace
18-
baseCompile(`@.caml:{'no apples'} 0 | {0} apple 0 | {n} apples 0`)
19-
})
20-
.on('error', event => {
21-
console.log(String(event.target))
22-
})
23-
.on('cycle', event => {
24-
console.log(String(event.target))
25-
})
26-
.run()
12+
bench(`compile complex message`, () => {
13+
// eslint-disable-next-line no-irregular-whitespace
14+
baseCompile(`@.caml:{'no apples'} 0 | {0} apple 0 | {n} apples 0`)
15+
})
2716

28-
displayMemoryUsage()
29-
}
17+
await run(args)
3018

31-
main().catch(err => {
32-
console.error(err)
33-
process.exit(1)
34-
})
19+
displayMemoryUsage()

benchmark/complex-jit-aot.mjs

+43-58
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ import {
88
translate
99
} from '@intlify/core-base'
1010
import { baseCompile } from '@intlify/message-compiler'
11-
import { createCommonJS } from 'mlly'
11+
import { bench, run } from 'mitata'
1212
import { dirname, resolve } from 'node:path'
1313
import { createI18n } from 'vue-i18n'
14-
import { displayMemoryUsage, readJson } from './utils.mjs'
15-
16-
const { require } = createCommonJS(import.meta.url)
17-
const { Suite } = require('benchmark')
14+
import { displayMemoryUsage, parseArgs, readJson } from './utils.mjs'
1815

16+
const args = parseArgs()
1917
function precompile(data) {
2018
const keys = Object.keys(data)
2119
keys.forEach(key => {
@@ -25,64 +23,51 @@ function precompile(data) {
2523
return data
2624
}
2725

28-
async function main() {
29-
const resources = await readJson(
30-
resolve(dirname('.'), './benchmark/complex.json')
31-
)
32-
const len = Object.keys(resources).length
33-
34-
console.log(`complex pattern on ${len} resources (JIT + AOT):`)
35-
console.log()
26+
const resources = await readJson(
27+
resolve(dirname('.'), './benchmark/complex.json')
28+
)
29+
const len = Object.keys(resources).length
30+
console.log(`complex pattern on ${len} resources (JIT + AOT):`)
3631

37-
resources['no apples'] = 'no apples'
32+
resources['no apples'] = 'no apples'
3833

39-
registerMessageCompiler(compile)
40-
const precompiledResources = precompile(resources)
34+
registerMessageCompiler(compile)
35+
const precompiledResources = precompile(resources)
4136

42-
const ctx = createCoreContext({
43-
locale: 'en',
44-
modifiers: {
45-
caml: val => val
46-
},
47-
messages: {
48-
en: precompiledResources
49-
}
50-
})
37+
const ctx = createCoreContext({
38+
locale: 'en',
39+
modifiers: {
40+
caml: val => val
41+
},
42+
messages: {
43+
en: precompiledResources
44+
}
45+
})
5146

52-
const i18n = createI18n({
53-
legacy: false,
54-
locale: 'en',
55-
modifiers: {
56-
caml: val => val
57-
},
58-
messages: {
59-
en: precompiledResources
60-
}
61-
})
47+
const i18n = createI18n({
48+
legacy: false,
49+
locale: 'en',
50+
modifiers: {
51+
caml: val => val
52+
},
53+
messages: {
54+
en: precompiledResources
55+
}
56+
})
6257

63-
new Suite('complex pattern')
64-
.add(`resolve time with core`, () => {
65-
translate(ctx, 'complex500', 2)
66-
})
67-
.add(`resolve time on composition`, () => {
68-
clearCompileCache()
69-
i18n.global.t('complex500', 2)
70-
})
71-
.add(`resolve time on composition with compile cache`, () => {
72-
i18n.global.t('complex500', 2)
73-
})
74-
.on('error', event => {
75-
console.log(String(event.target))
76-
})
77-
.on('cycle', event => {
78-
console.log(String(event.target))
79-
})
80-
.run()
58+
bench(`resolve time with core`, () => {
59+
translate(ctx, 'complex500', 2)
60+
})
8161

82-
displayMemoryUsage()
83-
}
62+
bench(`resolve time on composition`, () => {
63+
clearCompileCache()
64+
i18n.global.t('complex500', 2)
65+
})
8466

85-
main().catch(err => {
86-
console.error(err)
87-
process.exit(1)
67+
bench(`resolve time on composition with compile cache`, () => {
68+
i18n.global.t('complex500', 2)
8869
})
70+
71+
await run(args)
72+
73+
displayMemoryUsage()

benchmark/complex-jit.mjs

+45-60
Original file line numberDiff line numberDiff line change
@@ -7,71 +7,56 @@ import {
77
registerMessageCompiler,
88
translate
99
} from '@intlify/core-base'
10-
import { createCommonJS } from 'mlly'
10+
import { bench, run } from 'mitata'
1111
import { dirname, resolve } from 'node:path'
1212
import { createI18n } from 'vue-i18n'
13-
import { displayMemoryUsage, readJson } from './utils.mjs'
14-
15-
const { require } = createCommonJS(import.meta.url)
16-
const { Suite } = require('benchmark')
17-
18-
async function main() {
19-
const resources = await readJson(
20-
resolve(dirname('.'), './benchmark/complex.json')
21-
)
22-
const len = Object.keys(resources).length
23-
24-
console.log(`complex pattern on ${len} resources (JIT):`)
25-
console.log()
26-
27-
resources['no apples'] = 'no apples'
13+
import { displayMemoryUsage, parseArgs, readJson } from './utils.mjs'
14+
15+
const args = parseArgs()
16+
const resources = await readJson(
17+
resolve(dirname('.'), './benchmark/complex.json')
18+
)
19+
const len = Object.keys(resources).length
20+
console.log(`complex pattern on ${len} resources (JIT):`)
21+
22+
resources['no apples'] = 'no apples'
23+
24+
registerMessageCompiler(compile)
25+
26+
const ctx = createCoreContext({
27+
locale: 'en',
28+
modifiers: {
29+
caml: val => val
30+
},
31+
messages: {
32+
en: resources
33+
}
34+
})
2835

29-
registerMessageCompiler(compile)
36+
const i18n = createI18n({
37+
legacy: false,
38+
locale: 'en',
39+
modifiers: {
40+
caml: val => val
41+
},
42+
messages: {
43+
en: resources
44+
}
45+
})
3046

31-
const ctx = createCoreContext({
32-
locale: 'en',
33-
modifiers: {
34-
caml: val => val
35-
},
36-
messages: {
37-
en: resources
38-
}
39-
})
47+
bench(`resolve time with core`, () => {
48+
translate(ctx, 'complex500', 2)
49+
})
4050

41-
const i18n = createI18n({
42-
legacy: false,
43-
locale: 'en',
44-
modifiers: {
45-
caml: val => val
46-
},
47-
messages: {
48-
en: resources
49-
}
50-
})
51+
bench(`resolve time on composition`, () => {
52+
clearCompileCache()
53+
i18n.global.t('complex500', 2)
54+
})
5155

52-
new Suite('complex pattern')
53-
.add(`resolve time with core`, () => {
54-
translate(ctx, 'complex500', 2)
55-
})
56-
.add(`resolve time on composition`, () => {
57-
clearCompileCache()
58-
i18n.global.t('complex500', 2)
59-
})
60-
.add(`resolve time on composition with compile cache`, () => {
61-
i18n.global.t('complex500', 2)
62-
})
63-
.on('error', event => {
64-
console.log(String(event.target))
65-
})
66-
.on('cycle', event => {
67-
console.log(String(event.target))
68-
})
69-
.run()
56+
bench(`resolve time on composition with compile cache`, () => {
57+
i18n.global.t('complex500', 2)
58+
})
7059

71-
displayMemoryUsage()
72-
}
60+
await run(args)
7361

74-
main().catch(err => {
75-
console.error(err)
76-
process.exit(1)
77-
})
62+
displayMemoryUsage()

0 commit comments

Comments
 (0)