[英]Python: Is there a performance difference between `dist` and `sdist`?
Python setuptools
can create a source distribution: Python setuptools
可以创建源代码分发:
python setup.py sdist # create a source distribution (tarball, zip file, etc.)
Or a binary distribution: 或二进制分发:
python setup.py bdist # create a built (binary) distribution
As far as I understand, there should not be any performance difference: 据我了解,不应有任何性能差异:
bdist
installs the already-compiled .pyc
files from the binary package. bdist
从二进制包安装已编译的.pyc
文件。 sdist
compiles the .py
files to .pyc
files, and installs them. sdist
将.py
文件编译为.pyc
文件,然后安装它们。 When executed it should not matter how were the .pyc
files compiled - they should have the same performance. 执行时,编译.pyc
文件的方式无关紧要 - 它们应具有相同的性能。
Is there any performance difference between dist
and sdist
python packages? dist
和sdist
python包之间有任何性能差异吗?
If you have a pure Python code, the difference in time deploying will be slim. 如果您有纯Python代码,那么部署时间的差异将很小。 Note that there is no difference in performance between .py
and .pyc
, except that the latter will be read slightly faster the first time. 请注意, .py
和.pyc
之间的性能没有差别,除了后者第一次读取稍快一些。 The so called optimised .pyo
only strip the asserts, and optionally, get rid of the docstrings, so they are not very much optimised. 所谓的优化 .pyo
只剥离断言,并且可选地去除文档字符串,因此它们没有得到很好的优化。
The big difference comes when you have C files. 当你有C文件时,差别很大。 sdist will include them if properly referenced, but the user will need a working and appropiate compiler, Python header files, and so on. 如果正确引用, sdist将包含它们,但是用户将需要一个有效的编译器,Python头文件等等。 Also, you will have to take the time to build them on every client. 此外,您将不得不花时间在每个客户端上构建它们。 The same distribution will be valid for any platform you deploy in. 相同的分发对您部署的任何平台都有效。
On the other hand, bdist compiles the code once. 另一方面, bdist编译一次代码。 Installing in the client is immediate, as they don't need to build anything, and easier as they don't require a compiler installed. 在客户端安装是立竿见影的,因为它们不需要构建任何东西,并且因为它们不需要安装编译器而更容易。 The downside is that you have to build for that platform. 缺点是你必须为该平台构建。 Setuptools is capable of doing cross-compilation, provided you have installed and configured the right tools. 只要您安装并配置了正确的工具,Setuptools就能够进行交叉编译。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.