App Engine 上的 Python 2.7,simplejson 与原生 json,谁更快?
我了解到 simplejson 比 Python 中的原生 json 快得多,例如这个线程: json 和 simplejson Python 模块之间有什么区别?
但是,我当我在 App Engines 文档中读到 Python 2.7 时,我陷入了困境
使用原生 JSON 库,比 simplejson 快得多。
http://code.google.com/appengine/docs/python/ python27/newin27.html
所以现在我很困惑。其他地方似乎都说 simplejson 更好,但现在带有 Python 2.7 的 App Engine 说原生更快。什么给?
I've had the understanding that simplejson is much faster than the native json in Python, such as this thread:
What are the differences between json and simplejson Python modules?
However, I was just thrown for a loop when I read in App Engines documentation that with Python 2.7
Uses the native JSON library, which is much faster than simplejson.
http://code.google.com/appengine/docs/python/python27/newin27.html
So now I'm confused. Everywhere else it seems to say simplejson is better, but now App Engine with Python 2.7 says the native is faster. What gives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Python 2.7 运行时发布之前,App Engine 中包含的几乎每个模块以及您自己可以包含的每个模块都是纯 Python。在 2.7 版本中,
json
模块包括用 C 编写的加速,使其比您可以在 App Engine 上运行的任何simplejson
快得多。通常在 2.7 上使用
simplejson
的好处(主要是比最新版本的 Python 2.7 发布时更新的版本)不适用,因为您无法编译加速并将其部署到 App Engine。Before the release of the Python 2.7 runtime, nearly every module included with App Engine, and literally every module you could include yourself were pure python. With the 2.7 release, the
json
module includes speedups written in C, making it much faster than anysimplejson
you can run on App Engine.The benefits to using
simplejson
on 2.7 you get normally (mainly having a version that's newer than it was when the latest release of Python 2.7 was made) don't apply, since you can't compile the speedups in the latest version and deploy them to App Engine.当我迁移到 python 2.7 时,我发现自己被迫直接导入 json。在我的应用程序中,我必须从 simplejson 更改为这个。您可能会发现通常建议与“主要组件”保持最大兼容性,并且我认为 python 2.7 是我项目的主要用途/组件之一,其他组件是 Jinja2、WTForms 和 i18n 翻译。
I found myself forced to do a straight
import json
when I migrated to python 2.7. In my app I had to change from simplejson to this. You might find it generally recommendable to keep maximum compatibility with your "main component" and I consider python 2.7 one of my project's main uses / components where the others are Jinja2, WTForms and the i18n translations.