Closed noword closed 8 years ago
我尝试转换一个约3M大小的文本,速度非常非常慢。 我想问题是在 hanziconv.py 第58行开始的处理上。 python的字符串,不会增长,于是不断的会有新的final创建,老的final销毁。
改成这样
final = [] for c in text: index = fromMap.find(c) if index != -1: final.append(toMap[index]) else: final.append(c) return u"".join(final)
转换在5秒内完成。
Thanks noword! Looks like your way will be faster :). += on string is slow. Your change will be in next version
Done
我尝试转换一个约3M大小的文本,速度非常非常慢。 我想问题是在 hanziconv.py 第58行开始的处理上。 python的字符串,不会增长,于是不断的会有新的final创建,老的final销毁。
改成这样
转换在5秒内完成。