为什么python在Windows上这么慢? [英] Why is python so much slower on windows?
问题描述
我今天了解了火成岩,所以我决定看看我的各种环境如何.我在裸机上运行Windows的笔记本电脑上运行了pystones,并得到了这些结果
I learned about pystones today and so I decided to see what my various environments were like. I ran pystones on my laptop that is running windows on the bare metal and got these results
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from test import pystone
>>> for i in range(0,10):
... pystone.pystones()
...
(1.636334799754252, 30556.094026423627)
(2.1157907919853756, 23631.82607155689)
(2.5324817108003685, 19743.479207278437)
(2.541626695533182, 19672.4405231788)
(2.536022267835051, 19715.915208695682)
(2.540327088340973, 19682.50475676099)
(2.544761766911506, 19648.20465716261)
(2.540296805235016, 19682.739393664764)
(2.533851636391205, 19732.804905346253)
(2.536483186973612, 19712.3325148696)
然后我在我们的一些Linux VM上运行了它,并获得了2.7-3.4倍的更好性能.因此,我在笔记本电脑上启动了vmware Linux VM,并重新运行了相同的测试并获得了以下结果:
Then I ran it on some of our linux VMs and got 2.7-3.4 times better performance. So I fired up my vmware Linux VM on my laptop and reran the same test and got these results:
Python 2.7.2+ (default, Oct 4 2011, 20:03:08)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> for i in range(0,10):
... pystone.pystones()
...
(1.75, 28571.428571428572)
(1.17, 42735.042735042734)
(1.6600000000000001, 30120.48192771084)
(1.8399999999999999, 27173.913043478264)
(1.8200000000000003, 27472.52747252747)
(1.8099999999999987, 27624.30939226521)
(1.3099999999999987, 38167.938931297744)
(1.7800000000000011, 28089.88764044942)
(1.8200000000000038, 27472.527472527414)
(1.490000000000002, 33557.04697986573)
相对于在Windows下在同一裸机上运行的python,我不十分了解在同一窗口内运行的linux VM实际上更快.
I can't quite understand how the linux VM running inside the same windows is actually FASTER than python running on the same bare metal under windows.
Windows上的python有什么不同之处,它在裸机上的运行速度比在同一盒上运行Linux的VM内的运行慢?
What is so different about python on windows that it performs slower on the bare OS than it does inside a VM running Linux on the same box?
- 更多详细信息 Windows平台Win7x64 在两个平台上运行的32位python 在VMWare中运行Windows平台的32位linux VM
- More details Windows platform Win7x64 32 bit python running on both platforms 32 bit linux VM running the windows platform in VMWare
推荐答案
我无法回答您的问题,但是请考虑以下可能有所作为的事情:
I can't answer your question, however consider this list of things that could be making a difference:
-
您正在使用不同版本的Python. "2.7.2+"表示您的Linux Python是从版本控制检出而不是发行版中构建的.
You're using different versions of Python. "2.7.2+" indicates that your linux Python was built from a version control checkout rather than a release.
它们是使用不同的编译器进行编译的(可能是有意义的不同优化级别).
They were compiled with different compilers (and conceivably meaningfully different optimization levels).
您没有提到太多复制.可以想象,如果没有的话,那是幸.
You haven't mentioned reproducing this much. It's conceivable it was a fluke if you haven't.
您的VM可能计时不正确.
Your VM might be timing inaccurately.
您正在链接Python依赖关系的不同实现,尤其是Ignacio Vazquez-Abrams指出的libc.
You're linking different implementations of Python's dependencies, notably libc as Ignacio Vazquez-Abrams points out.
我不知道pystone的实际基准测试是什么样的,但是许多事情却以不同的方式工作-诸如Unicode处理或磁盘IO之类的事情可能是系统相关的因素.
I don't know what pystone's actual benchmarks are like, but many things work differently--things like unicode handling or disk IO could be system-dependent factors.
这篇关于为什么python在Windows上这么慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!