TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Speed tests for *json and cPickle in Python

40 点作者 j2d2j2d2大约 14 年前

7 条评论

thezilch大约 14 年前
And because caching systems are typically a means for speeding up reads, where the article only focuses on writes.<p>Python 2.5 -- including pickle's (faster) bin mode<p><pre><code> Starting simplejson dumps... done: 31.7636611462 Starting cjson encode... done: 3.80062890053 Starting pickle dumps... done: 10.4873199463 Starting pickle dumps (protocol=-1 -- force HIGHEST_PROTOCOL)... done: 5.98110699654 Starting simplejson loads... done: 138.709590197 Starting cjson decode... done: 1.85300803185 Starting pickle loads... done: 5.24735999107 Starting pickle loads (protocol=-1 -- force HIGHEST_PROTOCOL)... done: 3.66428518295</code></pre>
评论 #2398143 未加载
spenrose大约 14 年前
He doesn't use the cPickle binary format, which is significantly faster: <a href="http://docs.python.org/library/pickle.html#pickle.HIGHEST_PROTOCOL" rel="nofollow">http://docs.python.org/library/pickle.html#pickle.HIGHEST_PR...</a>
评论 #2398149 未加载
d0mine大约 14 年前
Python 2.7 on Ubuntu:<p><pre><code> $ python -mtimeit -s "from json import dumps; d = { 'foo': 'bar', 'food': 'barf', 'good': 'bars', 'dood': 'wheres your car?', 'wheres your car': 'dude?', } " "dumps(d)" 100000 loops, best of 3: 6.89 usec per loop $ python -mtimeit -s "from cPickle import dumps; d = { 'foo': 'bar', 'food': 'barf', 'good': 'bars', 'dood': 'wheres your car?', 'wheres your car': 'dude?', } " "dumps(d)" 100000 loops, best of 3: 7.78 usec per loop </code></pre> So `json` seems faster than `cPickle`. Right? Wrong!:<p><pre><code> $ python -mtimeit -s "from cPickle import dumps; d = { 'foo': 'bar', 'food': 'barf', 'good': 'bars', 'dood': 'wheres your car?', 'wheres your car': 'dude?', } " "dumps(d, -1)" 100000 loops, best of 3: 3.59 usec per loop</code></pre>
评论 #2397971 未加载
michaelfairley大约 14 年前
Apple and oranges (even though they're mostly used for the same thing). pickle is a Turing complete language used to recreate python objects, while json is only used for serialization. pickle is slightly more powerful, but should also not be used to load untrusted data. See <a href="http://nadiana.com/python-pickle-insecure" rel="nofollow">http://nadiana.com/python-pickle-insecure</a>
ericflo大约 14 年前
We were just talking about this a few weeks back, with a few more libraries compared with interesting results: <a href="https://convore.com/python/faster-json-library/" rel="nofollow">https://convore.com/python/faster-json-library/</a>
评论 #2398183 未加载
llambda大约 14 年前
I'm confused, is cjson still recommended? Is it still maintained? Its status seems ambiguous based on the PyPi discussion. Furthermore it seems there's a number of issues with cjson that need to be resolved...
评论 #2397922 未加载
评论 #2397863 未加载
评论 #2398438 未加载
评论 #2398230 未加载
antlong大约 14 年前
insane