Skip to content

Commit 3150fb6

Browse files
committed
add CodSpeed benchmark for unicode-segmenter/grapheme
1 parent cbd1a07 commit 3150fb6

File tree

4 files changed

+370
-2
lines changed

4 files changed

+370
-2
lines changed

.github/workflows/codspeed.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: CodSpeed
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
benchmarks:
12+
name: Run benchmarks
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: 24
20+
cache: yarn
21+
22+
- name: Install Dependencies
23+
run: yarn install --immutable
24+
25+
- name: Run benchmarks
26+
uses: CodSpeedHQ/action@v3
27+
with:
28+
run: node benchmark/grapheme/codspeed.mjs
29+
token: ${{ secrets.CODSPEED_TOKEN }}

benchmark/grapheme/codspeed.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { withCodSpeed } from '@codspeed/tinybench-plugin';
2+
import { Bench } from 'tinybench';
3+
4+
import { graphemeSegments } from '../../src/grapheme.js';
5+
6+
let testcases = [
7+
[
8+
'Lorem ipsum (ascii)',
9+
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
10+
],
11+
[
12+
'Emojis',
13+
'🌟📚✨🎉🚀🌍🎈🌸🍀🌻🎨💖🐾🍒🔮🍕🌙🌈🐢🍉💡📅🎶🎮🔥💤💼🚲🌼🔒💧💫',
14+
],
15+
[
16+
'Hindi',
17+
'राधा अपने बगीचे में फूलों को पानी देते हुए पक्षियों की चहचहाहट सुन रही थी, और वह सोच रही थी कि आज का दिन कितना शांत और सुंदर है।',
18+
],
19+
[
20+
'Demonic characters',
21+
'Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍A̴̵̜̰͔ͫ͗͢L̠ͨͧͩ͘G̴̻͈͍͔̹̑͗̎̅͛́Ǫ̵̹̻̝̳͂̌̌͘!͖̬̰̙̗̿̋ͥͥ̂ͣ̐́́͜͞',
22+
],
23+
[
24+
'Tweet text (combined)',
25+
'🚀 새로운 유니코드 분할기 라이브러리 \'unicode-segmenter\'를 소개합니다! 🔍 각종 언어의 문자를 정확하게 구분해주는 강력한 도구입니다. Check it out! 👉 [https://github.com/cometkim/unicode-segmenter] #Unicode #Programming 🌐',
26+
],
27+
[
28+
'Code snippet (combined)',
29+
`
30+
// 'unicode-segmenter' 라이브러리를 사용한 유니코드 문자 분할 예제 코드 🚀
31+
32+
// ESM supported!
33+
import { graphemeSegments } from 'unicode-segmenter/grapheme';
34+
35+
// 문자열을 유니코드 그래핌 단위로 분할하는 함수 예시
36+
function 문자분할테스트(문자열) {
37+
const 분할된문자들 = [...graphemeSegments(문자열)].map(({ segment }) => segment);
38+
console.log("분할된 유니코드 문자들:", 분할된문자들);
39+
}
40+
41+
// 테스트 문자열
42+
const 테스트문자열 = "안녕하세요! Welcome to the unicode-segementer library 📚";
43+
문자분할테스트(테스트문자열);
44+
`,
45+
],
46+
];
47+
48+
const bench = withCodSpeed(new Bench());
49+
50+
for (const [name, input] of testcases) {
51+
bench.add(name, () => {
52+
void [...graphemeSegments(input)];
53+
});
54+
}
55+
56+
await bench.run();
57+
console.table(bench.table());

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
"@babel/core": "^7.27.1",
119119
"@babel/plugin-transform-modules-commonjs": "^7.27.1",
120120
"@changesets/cli": "^2.29.4",
121+
"@codspeed/tinybench-plugin": "^4.0.1",
121122
"@formatjs/intl-segmenter": "11.7.10",
122123
"@mitata/counters": "^0.0.8",
123124
"@react-native/metro-babel-transformer": "^0.79.2",
@@ -135,6 +136,7 @@
135136
"os-browserify": "^0.3.0",
136137
"pretty-bytes": "^7.0.0",
137138
"rimraf": "^6.0.1",
139+
"tinybench": "^4.0.1",
138140
"typescript": "^5.8.3",
139141
"unicode-segmentation-wasm": "github:cometkim/unicode-segmentation-wasm#230eb74d320ea2f31f95b74ddb2567186d496587",
140142
"vite": "^6.3.5",

0 commit comments

Comments
 (0)