【发布时间】:2013-05-31 19:03:45
【问题描述】:
在 Python 中进行快速 YAML 解析的最新和最棒的是什么? Syck 是out of date,推荐使用 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
鉴于我的用例,我可以缓存已解析的对象,但即便如此,我仍然更喜欢更快的解决方案。
【问题讨论】:
-
嗯,我不知道 YAML 的使用率相对较低,而且不太活跃......下次可能只使用 JSON,因为我真正需要的是编码列表、数字、字符串和字典.. 我更喜欢 YAML 的外观,但是很好
-
PyYAML 有一个纯 Python 实现和一个 C 库的包装器。在进行基准测试之前,请确保 C 库可用,以便 PyYAML 可以使用它。
-
@delnan:啊,我不知道,因为该网站并没有说明这一点。我会尝试并回来查看。
标签: python performance yaml