我在我的电脑上运行了一个基准测试,在安装了C-native levenshtein backend和不安装C-native levenshtein backend的情况下,在~19k单词列表中找到8个单词的最佳候选词(使用pip install python_Levenshtein-0.12.0-cp34-none-win_amd64.whl),得到了以下计时:无C后端:
比较了151664个单词在48.591717004776秒(0.00032039058052521366秒/搜索)。在
已安装C后端:
比较了13.034106969833374秒(8.594067787895198e-05秒/搜索)中的151664个单词。在
这比我预期的快了4倍。在
结果如下:0 of 8: Compared 'Lemaire' > `[('L.', 90), ('Le', 90), ('A', 90), ('Re', 90), ('Em', 90)]`
1 of 8: Compared 'Peil' > `[('L.', 90), ('E.', 90), ('Pfeil', 89), ('Gampel', 76), ('Jo-pei', 76)]`
2 of 8: Compared 'Singleton' > `[('Eto', 90), ('Ng', 90), ('Le', 90), ('to', 90), ('On', 90)]`
3 of 8: Compared 'Tagoe' > `[('Go', 90), ('A', 90), ('T', 90), ('E.', 90), ('Sagoe', 80)]`
4 of 8: Compared 'Jgoun' > `[('Go', 90), ('Gon', 75), ('Journo', 73), ('Jaguin', 73), ('Gounaris', 72)]`
5 of 8: Compared 'Ben' > `[('Benfer', 90), ('Bence', 90), ('Ben-Amotz', 90), ('Beniaminov', 90), ('Benczak', 90)]`
6 of 8: Compared 'Porte' > `[('Porter', 91), ('Portet', 91), ('Porten', 91), ('Po', 90), ('Gould-Porter', 90)]`
7 of 8: Compared 'Nyla' > `[('L.', 90), ('A', 90), ('Sirichanya', 76), ('Neyland', 73), ('Greenleaf', 67)]`
下面是基准测试的python代码:
^{pr2}$