Skip to content

Commit

Permalink
chore: fix benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Dec 8, 2024
1 parent 959f271 commit 12aa95e
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 40 deletions.
2 changes: 1 addition & 1 deletion benchmark/compile.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createCommonJS } from 'mlly'
import { baseCompile } from '@intlify/message-compiler'
import { createCommonJS } from 'mlly'
import { displayMemoryUsage } from './utils.mjs'

const { require } = createCommonJS(import.meta.url)
Expand Down
16 changes: 9 additions & 7 deletions benchmark/complex-jit-aot.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
global.__INTLIFY_JIT_COMPILATION__ = true // set JIT mode for Node.js

import { createCommonJS } from 'mlly'
import { baseCompile } from '@intlify/message-compiler'
import {
translate,
createCoreContext,
clearCompileCache,
compile,
createCoreContext,
registerMessageCompiler,
clearCompileCache
translate
} from '@intlify/core-base'
import { baseCompile } from '@intlify/message-compiler'
import { createCommonJS } from 'mlly'
import { dirname, resolve } from 'node:path'
import { createI18n } from 'vue-i18n'
import { resolve, dirname } from 'path'
import { readJson, displayMemoryUsage } from './utils.mjs'
import { displayMemoryUsage, readJson } from './utils.mjs'

const { require } = createCommonJS(import.meta.url)
const { Suite } = require('benchmark')
Expand All @@ -34,6 +34,8 @@ async function main() {
console.log(`complex pattern on ${len} resources (JIT + AOT):`)
console.log()

resources['no apples'] = 'no apples'

registerMessageCompiler(compile)
const precompiledResources = precompile(resources)

Expand Down
14 changes: 8 additions & 6 deletions benchmark/complex-jit.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
global.__INTLIFY_JIT_COMPILATION__ = true // set JIT mode for Node.js

import { createCommonJS } from 'mlly'
import {
translate,
createCoreContext,
clearCompileCache,
compile,
createCoreContext,
registerMessageCompiler,
clearCompileCache
translate
} from '@intlify/core-base'
import { createCommonJS } from 'mlly'
import { dirname, resolve } from 'node:path'
import { createI18n } from 'vue-i18n'
import { resolve, dirname } from 'path'
import { readJson, displayMemoryUsage } from './utils.mjs'
import { displayMemoryUsage, readJson } from './utils.mjs'

const { require } = createCommonJS(import.meta.url)
const { Suite } = require('benchmark')
Expand All @@ -24,6 +24,8 @@ async function main() {
console.log(`complex pattern on ${len} resources (JIT):`)
console.log()

resources['no apples'] = 'no apples'

registerMessageCompiler(compile)

const ctx = createCoreContext({
Expand Down
12 changes: 7 additions & 5 deletions benchmark/complex.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createCommonJS } from 'mlly'
import {
translate,
clearCompileCache,
createCoreContext,
clearCompileCache
translate
} from '@intlify/core-base'
import { createCommonJS } from 'mlly'
import { dirname, resolve } from 'node:path'
import { createI18n } from 'vue-i18n'
import { resolve, dirname } from 'path'
import { readJson, displayMemoryUsage } from './utils.mjs'
import { displayMemoryUsage, readJson } from './utils.mjs'

const { require } = createCommonJS(import.meta.url)
const { Suite } = require('benchmark')
Expand All @@ -20,6 +20,8 @@ async function main() {
console.log(`complex pattern on ${len} resources (AOT):`)
console.log()

resources['no apples'] = 'no apples'

const ctx = createCoreContext({
locale: 'en',
modifiers: {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/index.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spawn } from 'child_process'
import { spawn } from 'node:child_process'

function run(pattner) {
return new Promise((resolve, reject) => {
Expand Down
14 changes: 7 additions & 7 deletions benchmark/simple-jit-aot.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
global.__INTLIFY_JIT_COMPILATION__ = true // set JIT mode for Node.js

import { createCommonJS } from 'mlly'
import { baseCompile } from '@intlify/message-compiler'
import {
translate,
createCoreContext,
clearCompileCache,
compile,
createCoreContext,
registerMessageCompiler,
clearCompileCache
translate
} from '@intlify/core-base'
import { baseCompile } from '@intlify/message-compiler'
import { createCommonJS } from 'mlly'
import { dirname, resolve } from 'node:path'
import { createI18n } from 'vue-i18n'
import { resolve, dirname } from 'path'
import { readJson, displayMemoryUsage } from './utils.mjs'
import { displayMemoryUsage, readJson } from './utils.mjs'

const { require } = createCommonJS(import.meta.url)
const { Suite } = require('benchmark')
Expand Down
12 changes: 6 additions & 6 deletions benchmark/simple-jit.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
global.__INTLIFY_JIT_COMPILATION__ = true // set JIT mode for Node.js

import { createCommonJS } from 'mlly'
import {
translate,
createCoreContext,
clearCompileCache,
compile,
createCoreContext,
registerMessageCompiler,
clearCompileCache
translate
} from '@intlify/core-base'
import { createCommonJS } from 'mlly'
import { dirname, resolve } from 'node:path'
import { createI18n } from 'vue-i18n'
import { resolve, dirname } from 'path'
import { readJson, displayMemoryUsage } from './utils.mjs'
import { displayMemoryUsage, readJson } from './utils.mjs'

const { require } = createCommonJS(import.meta.url)
const { Suite } = require('benchmark')
Expand Down
10 changes: 5 additions & 5 deletions benchmark/simple.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createCommonJS } from 'mlly'
import {
translate,
clearCompileCache,
createCoreContext,
clearCompileCache
translate
} from '@intlify/core-base'
import { createCommonJS } from 'mlly'
import { dirname, resolve } from 'node:path'
import { createI18n } from 'vue-i18n'
import { resolve, dirname } from 'path'
import { readJson, displayMemoryUsage } from './utils.mjs'
import { displayMemoryUsage, readJson } from './utils.mjs'

const { require } = createCommonJS(import.meta.url)
const { Suite } = require('benchmark')
Expand Down
2 changes: 1 addition & 1 deletion benchmark/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs/promises'
import fs from 'node:fs/promises'

export async function readJson(path) {
const data = await fs.readFile(path, 'utf8')
Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@
"url": "https://github.com/inlitify/vue-i18n/issues"
},
"scripts": {
"benchmark": "node ./benchmark/index.mjs",
"bench": "node ./benchmark/index.mjs",
"bench:compile": "node ./benchmark/compile.mjs",
"bench:simple": "node ./benchmark/simple.mjs",
"bench:simple-jit": "node ./benchmark/simple-jit.mjs",
"bench:simple-jit-aot": "node ./benchmark/simple-jit-aot.mjs",
"bench:complex": "node ./benchmark/complex.mjs",
"bench:complex-jit": "node ./benchmark/complex-jit.mjs",
"bench:complex-jit-aot": "node ./benchmark/complex-jit-aot.mjs",
"build": "tsx ./scripts/build.ts",
"build:explorer": "pnpm --filter @intlify/message-format-explorer build",
"build:size": "pnpm build && run-p build:size-*",
Expand Down

0 comments on commit 12aa95e

Please sign in to comment.