forked from FooSoft/yomichan
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add basic benches * add package.json script * fix header * add codspeed plugin * add benchmark GitHub action * add env * revert change * merge upstream * update names
- Loading branch information
Showing
10 changed files
with
447 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Performance Benchmarks | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
merge_group: | ||
workflow_dispatch: | ||
jobs: | ||
benchmark: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: "package.json" | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Build Libs | ||
run: npm run build-libs | ||
|
||
- name: Run Benchmarks | ||
uses: CodSpeedHQ/action@v2 | ||
with: | ||
token: ${{ secrets.CODSPEED_TOKEN }} | ||
run: npm run bench |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "ES2022", | ||
"target": "ES2022", | ||
"checkJs": true, | ||
"moduleResolution": "node", | ||
"strict": true, | ||
"strictNullChecks": true, | ||
"noImplicitAny": true, | ||
"strictPropertyInitialization": true, | ||
"suppressImplicitAnyIndexErrors": false, | ||
"skipLibCheck": false, | ||
"baseUrl": ".", | ||
"paths": { | ||
"*": ["../types/ext/*"], | ||
"dev/*": ["../types/dev/*"], | ||
"benches/*": ["../types/benches/*"], | ||
"rollup/parseAst": ["../types/other/rollup-parse-ast"], | ||
"ext/json-schema": ["../types/ext/json-schema"], | ||
"json-schema": ["json-schema"] | ||
}, | ||
"types": [ | ||
"chrome", | ||
"firefox-webext-browser", | ||
"handlebars", | ||
"jszip", | ||
"parse5", | ||
"wanakana" | ||
] | ||
}, | ||
"include": [ | ||
"**/*.js", | ||
"../ext/**/*.js", | ||
"../types/ext/**/*.ts", | ||
"../types/dev/**/*.ts", | ||
"../types/benches/**/*.ts", | ||
"../types/other/globals.d.ts" | ||
], | ||
"exclude": [ | ||
"../node_modules", | ||
"../dev/lib" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright (C) 2023-2024 Yomitan Authors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import fs from 'fs'; | ||
import {fileURLToPath} from 'node:url'; | ||
import path from 'path'; | ||
import {bench, describe} from 'vitest'; | ||
import {parseJson} from '../dev/json.js'; | ||
import {LanguageTransformer} from '../ext/js/language/language-transformer.js'; | ||
|
||
const dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
|
||
/** @type {import('language-transformer').LanguageTransformDescriptor} */ | ||
const descriptor = parseJson(fs.readFileSync(path.join(dirname, '..', 'ext', 'data/language/japanese-transforms.json'), {encoding: 'utf8'})); | ||
const languageTransformer = new LanguageTransformer(); | ||
languageTransformer.addDescriptor(descriptor); | ||
|
||
describe('Language transformer basic tests', () => { | ||
const adjectiveInflections = [ | ||
'愛しい', | ||
'愛しそう', | ||
'愛しすぎる', | ||
'愛しかったら', | ||
'愛しかったり', | ||
'愛しくて', | ||
'愛しく', | ||
'愛しくない', | ||
'愛しさ', | ||
'愛しかった', | ||
'愛しくありません', | ||
'愛しくありませんでした', | ||
'愛しき' | ||
]; | ||
|
||
const verbInflections = [ | ||
'食べる', | ||
'食べます', | ||
'食べた', | ||
'食べました', | ||
'食べて', | ||
'食べられる', | ||
'食べられる', | ||
'食べさせる', | ||
'食べさせられる', | ||
'食べろ', | ||
'食べない', | ||
'食べません', | ||
'食べなかった', | ||
'食べませんでした', | ||
'食べなくて', | ||
'食べられない', | ||
'食べられない', | ||
'食べさせない', | ||
'食べさせられない', | ||
'食べ', | ||
'食べれば', | ||
'食べちゃう', | ||
'食べちまう', | ||
'食べなさい', | ||
'食べそう', | ||
'食べすぎる', | ||
'食べたい', | ||
'食べたら', | ||
'食べたり', | ||
'食べず', | ||
'食べぬ', | ||
'食べ', | ||
'食べましょう', | ||
'食べよう', | ||
'食べとく', | ||
'食べている', | ||
'食べておる', | ||
'食べてる', | ||
'食べとる', | ||
'食べてしまう' | ||
]; | ||
|
||
const inflectionCombinations = [ | ||
'抱き抱えていなければ', | ||
'抱きかかえていなければ', | ||
'打ち込んでいませんでした', | ||
'食べさせられたくなかった' | ||
]; | ||
|
||
bench('transformations', () => { | ||
for (const transform of [...adjectiveInflections, ...verbInflections, ...inflectionCombinations]) { | ||
languageTransformer.transform(transform); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.