parse-pinyin 1.1.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -110,15 +110,47 @@ console.log(toHanzi('zhong'));
|
|
|
110
110
|
|
|
111
111
|
## 性能对比
|
|
112
112
|
|
|
113
|
-
在典型的使用场景中,parse-pinyin
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
113
|
+
在典型的使用场景中,parse-pinyin 相比其他拼音库具有显著的性能优势:
|
|
114
|
+
|
|
115
|
+
### 与 pinyin-pro 对比
|
|
116
|
+
|
|
117
|
+
实际测试结果(硬件:Apple M1 Pro,Node.js v18.17.0):
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
// 测试代码
|
|
121
|
+
import { toPinyin } from 'parse-pinyin';
|
|
122
|
+
import { pinyin } from 'pinyin-pro';
|
|
123
|
+
|
|
124
|
+
const testChars = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十',
|
|
125
|
+
'中', '国', '人', '民', '大', '家', '好', '学', '习', '天',
|
|
126
|
+
'行', '动', '快', '乐', '幸', '福', '健', '康', '安', '全'];
|
|
127
|
+
|
|
128
|
+
console.time('parse-pinyin');
|
|
129
|
+
for (let i = 0; i < 10000; i++) {
|
|
130
|
+
testChars.forEach(char => {
|
|
131
|
+
toPinyin(char);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
console.timeEnd('parse-pinyin');
|
|
135
|
+
// 输出: parse-pinyin: 13.269ms
|
|
136
|
+
|
|
137
|
+
console.time('pinyin-pro');
|
|
138
|
+
for (let i = 0; i < 10000; i++) {
|
|
139
|
+
testChars.forEach(char => {
|
|
140
|
+
pinyin(char, { toneType: 'symbol' });
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
console.timeEnd('pinyin-pro');
|
|
144
|
+
// 输出: pinyin-pro: 166.447ms
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 性能测试结果
|
|
148
|
+
|
|
149
|
+
| 测试项目 | parse-pinyin | pinyin-pro | 性能提升 |
|
|
150
|
+
|---------|-------------|------------|---------|
|
|
151
|
+
| 单字符拼音转换 (10,000次) | 13.27ms | 166.45ms | 12.54x |
|
|
152
|
+
| 批量处理 (100,000字符) | ~130ms | ~1660ms | 12.77x |
|
|
153
|
+
|
|
122
154
|
|
|
123
155
|
## 浏览器使用
|
|
124
156
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "parse-pinyin",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.2.4",
|
|
4
|
+
"description": "一个高效的汉字拼音查询库,兼容浏览器和nodejs,提供ESM、commonjs、iife格式的构建,支持拼音反查",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.mjs",
|