Skip to content

Commit

Permalink
add benches
Browse files Browse the repository at this point in the history
  • Loading branch information
Casheeew committed Jan 28, 2024
2 parents 1b9422d + ff4ce8e commit 6cedadc
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"project": [
"./jsconfig.json",
"./dev/jsconfig.json",
"./test/jsconfig.json"
"./test/jsconfig.json",
"./benches/jsconfig.json"
]
},
"env": {
Expand Down
104 changes: 104 additions & 0 deletions benches/deinflector.bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright (C) 2023 Yomitan Authors
* Copyright (C) 2020-2022 Yomichan 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';

Check failure on line 19 in benches/deinflector.bench.js

View workflow job for this annotation

GitHub Actions / test

incorrect header
import {fileURLToPath} from 'node:url';
import path from 'path';
import {bench, describe} from 'vitest';
import {parseJson} from '../dev/json.js';
import {Deinflector} from '../ext/js/language/deinflector.js';

const dirname = path.dirname(fileURLToPath(import.meta.url));

/** @type {import('deinflector').ReasonsRaw} */
const deinflectionReasons = parseJson(fs.readFileSync(path.join(dirname, '..', 'ext', 'data/deinflect.json'), {encoding: 'utf8'}));
const deinflector = new Deinflector(deinflectionReasons);

describe('Deinflector basic tests', () => {
const adjectiveInflections = [
'愛しい',
'愛しそう',
'愛しすぎる',
'愛しかったら',
'愛しかったり',
'愛しくて',
'愛しく',
'愛しくない',
'愛しさ',
'愛しかった',
'愛しくありません',
'愛しくありませんでした',
'愛しき'
];

const verbInflections = [
'食べる',
'食べます',
'食べた',
'食べました',
'食べて',
'食べられる',
'食べられる',
'食べさせる',
'食べさせられる',
'食べろ',
'食べない',
'食べません',
'食べなかった',
'食べませんでした',
'食べなくて',
'食べられない',
'食べられない',
'食べさせない',
'食べさせられない',
'食べ',
'食べれば',
'食べちゃう',
'食べちまう',
'食べなさい',
'食べそう',
'食べすぎる',
'食べたい',
'食べたら',
'食べたり',
'食べず',
'食べぬ',
'食べ',
'食べましょう',
'食べよう',
'食べとく',
'食べている',
'食べておる',
'食べてる',
'食べとる',
'食べてしまう'
];

const inflectionCombinations = [
'抱き抱えていなければ',
'抱きかかえていなければ',
'打ち込んでいませんでした',
'食べさせられたくなかった'
];

bench('deinflection', () => {
for (const inflection of [...adjectiveInflections, ...verbInflections, ...inflectionCombinations]) {
deinflector.deinflect(inflection);
}
});
});
43 changes: 43 additions & 0 deletions benches/jsconfig.json
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"
]
}
3 changes: 2 additions & 1 deletion test/data/json.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
{"path": "test/data/dictionaries/invalid-dictionary6/index.json", "ignore": true},
{"path": "test/jsconfig.json", "ignore": true},
{"path": "test/data/vitest.write.config.json", "ignore": true},
{"path": "benches/jsconfig.json", "ignore": true},

{
"path": "dev/data/manifest-variants.json",
Expand Down Expand Up @@ -184,4 +185,4 @@
"schema": "ext/data/schemas/dictionary-term-meta-bank-v3-schema.json"
}
]
}
}
1 change: 1 addition & 0 deletions test/json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function getJsconfigPath(jsconfigType) {
switch (jsconfigType) {
case 'dev': path = '../dev/jsconfig.json'; break;
case 'test': path = '../test/jsconfig.json'; break;
case 'benches': path = '../benches/jsconfig.json'; break;
default: path = '../jsconfig.json'; break;
}
return join(dirname, path);
Expand Down
2 changes: 1 addition & 1 deletion types/test/json.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ export type JsonFileParseInfo = {

export type AjvSchema = Schema;

export type JsconfigType = 'main' | 'dev' | 'test';
export type JsconfigType = 'main' | 'dev' | 'test' | 'benches';

0 comments on commit 6cedadc

Please sign in to comment.