在 Python 中进行快速 YAML 解析的最新和最棒的是什么?Syck 已经过时了,建议使用 PyYaml,但是 PyYaml 速度很慢,并且存在 GIL 问题:
>>> def xit(f, x):
import threading
for i in xrange(x):
threading.Thread(target=f).start()
>>> def stressit():
start = time.time()
res = yaml.load(open(path_to_11000_byte_yaml_file))
print "Took %.2fs" % (time.time() - start,)
>>> xit(stressit, 1)
Took 0.37s
>>> xit(stressit, 2)
Took 1.40s
Took 1.41s
>>> xit(stressit, 4)
Took 2.98s
Took 2.98s
Took 2.99s
Took 3.00s
鉴于我的用例,我可以缓存解析的对象,但即便如此,我仍然更喜欢更快的解决方案。