应用程序引擎上的Python 2.7, simplejson vs原生json,谁更快?

时间:2021-10-03 01:59:34

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?

我已经理解了simplejson比Python中的本机json要快得多,比如这个线程:json和simplejson Python模块之间有什么区别?

However, I was just thrown for a loop when I read in App Engines documentation that with Python 2.7

然而,当我在应用程序引擎文档中看到Python 2.7时,我只是被抛出了一个循环

Uses the native JSON library, which is much faster than simplejson.

使用本机JSON库,它比simplejson快得多。

http://code.google.com/appengine/docs/python/python27/newin27.html

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?

现在我困惑。其他地方似乎都说simplejson更好,但是现在Python 2.7的App Engine说本地语言更快。到底发生了什么事?

2 个解决方案

#1


23  

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 any simplejson you can run on App Engine.

在Python 2.7运行时发布之前,几乎所有的模块都包含在App Engine中,几乎所有的模块都是纯Python。在2.7版中,json模块包含用C编写的加速,比任何在App Engine上运行的simplejson都要快得多。

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.

在2.7上使用simplejson的好处(主要有一个版本比最新版本的Python 2.7发布时要更新)不适用,因为您无法在最新版本中编译速度,并将它们部署到App Engine。

#2


4  

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.

当我迁移到python 2.7时,我发现自己*直接导入json。在我的应用中,我必须从simplejson更改为这个。您可能会发现它通常推荐与“主组件”保持最大的兼容性,我认为python 2.7是我的项目的主要用途/组件之一,其他用途包括Jinja2、WTForms和i18n转换。

#1


23  

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 any simplejson you can run on App Engine.

在Python 2.7运行时发布之前,几乎所有的模块都包含在App Engine中,几乎所有的模块都是纯Python。在2.7版中,json模块包含用C编写的加速,比任何在App Engine上运行的simplejson都要快得多。

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.

在2.7上使用simplejson的好处(主要有一个版本比最新版本的Python 2.7发布时要更新)不适用,因为您无法在最新版本中编译速度,并将它们部署到App Engine。

#2


4  

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.

当我迁移到python 2.7时,我发现自己*直接导入json。在我的应用中,我必须从simplejson更改为这个。您可能会发现它通常推荐与“主组件”保持最大的兼容性,我认为python 2.7是我的项目的主要用途/组件之一,其他用途包括Jinja2、WTForms和i18n转换。