Merge pull request #96 from TonyRL/main

feat: update benchmark
This commit is contained in:
zhoulixiang
2023-05-17 08:12:00 +08:00
committed by GitHub
3 changed files with 44 additions and 16 deletions

View File

@@ -63,14 +63,14 @@ pinyin('汉语拼音', { pattern: 'final' }); // 'àn ǔ īn īn'
### 性能及准确率
以下是 `pinyin-pro``pinyin` 包对于汉字转换的速度及准确率对比,更多细节可以参考
以下是 `pinyin-pro``pinyin``@napi-rs/pinyin` 包对于汉字转换的速度及准确率对比,更多细节可以参考
| 对比项 | pinyin | pinyin-pro |
| ------------------- | ---------------- | ---------- |
| 准确率 | 95.894% | 99.744% |
| 5k 字转换所需时间 | 190.192ms | 7.199ms |
| 1w 字转换所需时间 | 内存溢出转换失败 | 13.199ms |
| 100w 字转换所需时间 | 内存溢出转换失败 | 646.973ms |
| 对比项 | pinyin | pinyin-pro | @napi-rs/pinyin |
| ------------------ | ---------------- | ---------- | --------------- |
| 准确率 | 97.844% | 99.744% | 97.433% |
| 5k 字转换所需时间 | 489.252ms | 5.909ms | 115.723ms |
| 1w 字转换所需时间 | 511.573ms | 15.260ms | 115.887ms |
| 100w 字转换所需时间 | 内存溢出转换失败 | 595.131ms | 570.994s |
### 反馈

View File

File diff suppressed because one or more lines are too long

View File

@@ -1,4 +1,7 @@
const { pinyin } = require('../dist');
const { pinyin: pinyinPro } = require('../dist');
const { pinyin } = require('pinyin');
const { pinyin: nApiPinyin } = require('@napi-rs/pinyin');
const text = `
@@ -9533,7 +9536,17 @@ const text = `
上面没有名字但是多年前有只手用铅笔在上面写了四行诗在雨露和尘土的洗刷下已渐渐地模糊了如今可能已经没有了他安息了尽管命运多舛他仍偷生失去了他的天使他便丧生事情是自然而然地发生正如夜幕降临太阳西沉
`.slice(0, 5000);
const label = `pinyin-pro 转换 ${text.length} 字数时间`;
console.time(label);
pinyin(text);
console.timeEnd(label);
const pinyinProLabel = `pinyin-pro 转换 ${text.length} 字数时间`;
console.time(pinyinProLabel);
pinyinPro(text);
console.timeEnd(pinyinProLabel);
const pinyinLabel = `pinyin 转换 ${text.length} 字数时间`;
console.time(pinyinLabel);
pinyin(text, { segment: true });
console.timeEnd(pinyinLabel);
const nApiPinyinLabel = `@napi-rs/pinyin 转换 ${text.length} 字数时间`;
console.time(nApiPinyinLabel);
nApiPinyin(text, { segment: true });
console.timeEnd(nApiPinyinLabel);