Skip to content

Commit

Permalink
bench mark를 실행할 수 있도록 환경을 세팅합니다 (#261)
Browse files Browse the repository at this point in the history
* bench mark를 실행할 수 있도록 환경을 세팅합니다

* bench mark를 실행할 수 있도록 환경을 세팅합니다

* ignore bench lint

* bench mark 에제를 더 추가합니다

* revert josa
  • Loading branch information
okinawaa authored Nov 1, 2024
1 parent 821267d commit ab36228
Show file tree
Hide file tree
Showing 8 changed files with 763 additions and 405 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module.exports = {
'shared-node-browser': true,
},

ignorePatterns: ['benchmarks/**/*'],

parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: { jsx: true },
Expand Down
19 changes: 19 additions & 0 deletions benchmarks/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "benchmarks",
"private": true,
"scripts": {
"check-bundle-size": "vitest --update"
},
"dependencies": {
"@faker-js/faker": "^9.1.0",
"auto-josa": "^1.0.0",
"es-hangul": "workspace:^",
"esbuild": "0.23.0",
"josa": "^3.0.1",
"k-popo": "^2.0.5",
"vitest": "^2.1.2"
},
"devDependencies": {
"@types/josa": "^3"
}
}
61 changes: 61 additions & 0 deletions benchmarks/performance/josa.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { fakerKO as faker } from '@faker-js/faker';

import { josa as autoJosa } from 'auto-josa';
import { josa as esHangulJosa } from 'es-hangul';
import { josa } from 'josa';
import { ko } from 'k-popo';
import { bench, describe } from 'vitest';

const name = faker.person.firstName();

describe('하나의 조사', () => {
bench('es-hangul', () => {
esHangulJosa(name, '이/가');
});

bench('auto-josa', () => {
autoJosa`${name}이`;
});

bench('josa', () => {
josa(`${name}#{이}`);
});

bench('k-popo', () => {
ko`${name}(이)가`;
});
});

const city = faker.location.city();
const street = faker.location.street();
const noun = faker.word.noun();

describe(`네개의 조사 ${name}이/가 ${noun}을/를 ${city}은/는 ${street}와/과`, () => {
bench('es-hangul', () => {
esHangulJosa(noun, '이/가');
esHangulJosa(name, '을/를');
esHangulJosa(city, '은/는');
esHangulJosa(street, '와/과');
});

bench('auto-josa', () => {
autoJosa`${noun}이`;
autoJosa`${name}을`;
autoJosa`${city}은`;
autoJosa`${street}와`;
});

bench('josa', () => {
josa(`${noun}#{이}`);
josa(`${name}#{을}`);
josa(`${city}#{은}`);
josa(`${street}#{와}`);
});

bench('k-popo', () => {
ko`${noun}(이)가`;
ko`${name}(을)를`;
ko`${city}(은)는`;
ko`${street}(와)과`;
});
});
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
],
"workspaces": [
".",
"docs"
"docs",
"benchmarks"
],
"scripts": {
"attw": "attw --pack",
Expand All @@ -53,7 +54,8 @@
"typecheck": "tsc --noEmit",
"docs:dev": "yarn workspace docs dev",
"docs:build": "yarn workspace docs build",
"docs:start": "yarn workspace docs start"
"docs:start": "yarn workspace docs start",
"bench": "vitest bench"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.3",
Expand All @@ -65,8 +67,8 @@
"@types/node": "^20.11.30",
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"@vitest/coverage-istanbul": "^1.5.0",
"@vitest/ui": "^1.5.0",
"@vitest/coverage-istanbul": "^2.1.2",
"@vitest/ui": "^2.1.2",
"broken-link-checker": "^0.7.8",
"eslint": "^8.57.0",
"eslint-config-prettier": "^8.5.0",
Expand All @@ -75,7 +77,7 @@
"publint": "^0.2.7",
"tsup": "^8.0.2",
"typescript": "^5.4.3",
"vitest": "^1.5.0"
"vitest": "^2.1.2"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 2 additions & 2 deletions src/josa/josa.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { disassembleCompleteCharacter } from '../disassembleCompleteCharacter';
import { disassembleCompleteCharacter } from '@/disassembleCompleteCharacter';
import { hasBatchim } from '../hasBatchim';

type JosaOption =
Expand Down Expand Up @@ -37,7 +37,7 @@ function josaPicker(word: string, josa: JosaOption): string {
const has받침 = hasBatchim(word);
let index = has받침 ? 0 : 1;

const is종성ㄹ = disassembleCompleteCharacter(word[word.length - 1])?.jongseong === 'ㄹ';
const is종성ㄹ = has받침 && disassembleCompleteCharacter(word[word.length - 1])?.jongseong === 'ㄹ';

const isCaseOf로 = has받침 && is종성ㄹ && 로_조사.includes(josa);

Expand Down
Empty file added src/josa/josaPicker.ts
Empty file.
1 change: 0 additions & 1 deletion vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export default defineConfig({
},
test: {
name: packageJson.name,
dir: './src',
globals: true,
coverage: {
provider: 'istanbul',
Expand Down
Loading

0 comments on commit ab36228

Please sign in to comment.