Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

算法优化尝试 #53

Open
hotoo opened this issue Aug 3, 2015 · 6 comments
Open

算法优化尝试 #53

hotoo opened this issue Aug 3, 2015 · 6 comments
Assignees
Milestone

Comments

@hotoo
Copy link
Owner

hotoo commented Aug 3, 2015

@TooBug 有很好的一个 PR #26 ,这个 PR 其实早已经无法合并进来了,但是我一直没舍得关掉,因为有很好的参考价值。

  • 二进制字典。
  • 二分法查找。

我计划近期也尝试更新使用这两者,另外其他的一些技术(比如偏移量)也会进行尝试。

如果尝试的结果满足甚至超出预期,会合并且升级版本到 3.0.x

目前 @TooBug/pinyin 是每个汉字转换都会 fs.openSync 二进制字典,我计划只打开一次,必要的话直接装载到内存(不知道和现在直接装载整个 JSON 字典差异有多大)。

谢谢 @TooBug,并 Close #26.

@hotoo hotoo self-assigned this Aug 3, 2015
@hotoo hotoo modified the milestone: 3.0.0 Aug 3, 2015
@hotoo
Copy link
Owner Author

hotoo commented Aug 5, 2015

现有数据对比:

short(time) short(memory) long(time) long(memory)
@TooBug/pinyin@0.2.2 13ms 2052096 (1.96M) 344ms 10543104 (10.05M)
@hotoo/pinyin@2.5.1 109ms 30367744 (28.96M) 105ms 31322112 (29.87M)
@TooBug/pinyin@0.2.2 (only calc) 5ms 2166784 (2.07M) 321ms 10887168 (10.38M)
@hotoo/pinyin@2.5.1 (only calc) 1ms 30130176 (28.73M) 6ms 31363072 (29.91M)
@TooBug/pinyin@0.2.2 (twice long, only calc) 625ms 10817536 (10.32M)
@hotoo/pinyin@2.5.1 (twice long, only calc) 7ms 31989760 (30.51M)
@TooBug/pinyin@0.2.2 (tenfold long, only calc) 2984ms 27246592 (25.98M)
@hotoo/pinyin@2.5.1 (tenfold long, only calc) 21ms 33804288 (32.24M)
@TooBug/pinyin@0.2.2 (twenty times long, only calc) 5981ms 43524096 (41.51M)
@hotoo/pinyin@2.5.1 (twenty times long, only calc) 38ms 37453824 (35.72.24M)

2016-01-23 21 10 46

从现有的数据来看,TooBug 的版本除了初始化 pinyin 模块性能较高之外,其他还是可圈可点(当然 TooBug 的版本还有些可优化的地方)。

@hotoo hotoo added the Reference label Aug 5, 2015
@TooBug
Copy link

TooBug commented Aug 5, 2015

Yeah,加油!3.0性能表现好的话再用回来,减少生态中的重复模块!

@hotoo
Copy link
Owner Author

hotoo commented Aug 5, 2015

pinyin@2.5 开始默认关闭汉语分词,所以除了使用内存较多(但比较稳定,30M 左右,开启分词另算),一旦模块加载好,计算转换成拼音的速度还是比 @TooBug/pinyin 快很多的。

而且 @TooBug/pinyin 的内存使用和计算转换耗时随着字符串的增长而增长的非常快(@hotoo/pinyin 会比较稳定),看上面数据。

如果你不开启分词,并且预装载好 pinyin 模块,现在就可以使用 @hotoo/pinyin 了。

3.0 主要考虑在保持计算性能没有明显下降的情况下,尽量减少内存使用。

@breezewish
Copy link

breezewish commented Feb 6, 2016

https://github.com/breeswish/pinyinlite

前端项目需要,写了一个只做输出不做内容判断、词库比较大的拼音库。其中用到的优化,在内存和时间上都取得了很好的效果,可以考虑 port 一下 :-)

@hotoo
Copy link
Owner Author

hotoo commented Feb 13, 2016

@summerwish 好的,我抽空研究下你的作品。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants