Windows 上的 Python 性能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1842798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:32:09  来源:igfitidea点击:

Python Performance on Windows

pythonwindowsperformancemacosmercurial

提问by Frank V

Is Python generally slower on Windows vs. a *nix machine? Python seems to blaze on my Mac OS X machine whereas it seemsto run slower on my Window's Vista machine. The machines are similar in processing power and the vista machine has 1GBs more memory.

与 *nix 机器相比,Python 在 Windows 上通常更慢吗?Python 在我的 Mac OS X 机器上似乎很火爆,而在我的 Window 的 Vista 机器上它似乎运行得更慢。这些机器的处理能力相似,vista 机器的内存多 1GB。

I particularly notice this in Mercurial but I figure this may simply be how Mercurial is packaged on windows.

我特别注意到 Mercurial 中的这一点,但我认为这可能只是 Mercurial 在 Windows 上的打包方式。

采纳答案by Frank V

I wanted to follow up on this and I found something that I believe is 'my answer'. It appears that Windows (vista, which is what I notice this on) is not as fast in handling files. This was mentioned by tony-p-lee.

我想跟进这个,我发现了一些我认为是“我的答案”的东西。看来Windows(vista,这是我注意到的)在处理文件方面没有那么快。这是tony-p-lee 提到的。

I found this comparisons of Ubuntu vs Vista vs Win7. Their results are interesting and like they say, you need to take the results with a grain of salt. But I think the results lead me to the cause. Python, which I feel was indirectly tested, is about equivalent if not a tad-bit faster on Windows.. See the section "Richards benchmark".

我发现了Ubuntu vs Vista vs Win7 的比较。他们的结果很有趣,就像他们说的那样,您需要对结果持保留态度。但我认为结果使我找到了原因。我觉得 Python 是间接测试过的,如果不是在 Windows 上快一点的话,它几乎是等效的。请参阅“Richards 基准测试”部分。

Here is their graph for file transfers:

这是他们的文件传输图表:

Graph - small file HD to HD
(source: tuxradar.com)

图形 - 小文件 HD 到 HD
(来源:tuxradar.com

I think this specifically help address the question because Hg is really just a series of file reads, copies and overall handling. Its likely this is causing the delay.

我认为这特别有助于解决这个问题,因为 Hg 实际上只是一系列文件读取、复制和整体处理。这很可能是导致延迟的原因。

http://www.tuxradar.com/content/benchmarked-ubuntu-vs-vista-vs-windows-7

http://www.tuxradar.com/content/benchmarked-ubuntu-vs-vista-vs-windows-7

回答by Chris Smith

No real numbers here but it certainly feels like the start up time is slower on Windows platforms. I regularly switch between Ubuntu at home and Windows 7 at work and it's an order of magnitude faster starting up on Ubuntu, despite my work machine being at least 4x the speed.

这里没有实际数字,但在 Windows 平台上确实感觉启动时间较慢。我经常在家里的 Ubuntu 和工作中的 Windows 7 之间切换,尽管我的工作机器至少是速度的 4 倍,但在 Ubuntu 上启动速度要快一个数量级。

As for runtime performance, it feels about the same for "quiet" applications. If there are any GUI operations using Tk on Windows, they are definitely slower. Any console applications on windows are slower, but this is most likely due to the Windows cmd rendering being slow more than python running slowly.

至于运行时性能,对于“安静”的应用程序,感觉大致相同。如果在 Windows 上有任何使用 Tk 的 GUI 操作,它们肯定会更慢。Windows 上的任何控制台应用程序都比较慢,但这很可能是因为 Windows cmd 渲染比 Python 运行慢得多。

回答by tony-p-lee

Maybe the python has more depend on a lot of files open (import different modules).

也许python更多地依赖于打开的大量文件(导入不同的模块)。

Windows doesn't handle file open as efficiently as Linux.

Windows 不像 Linux 那样有效地处理文件打开。

Or maybe Linux probably have more utilities depend on python and python scripts/modules are more likely to be buffered in the system cache.

或者 Linux 可能有更多的实用程序依赖于 python 并且 python 脚本/模块更有可能被缓冲在系统缓存中。

回答by Soviut

I run Python locally on Windows XP and 7 as well as OSX on my Macbook. I've seen no noticable performance differences in the command line interpreter, wx widget apps run the same, and Django apps also perform virtually identically.

我在 Windows XP 和 7 以及 Macbook 上的 OSX 上本地运行 Python。我在命令行解释器中没有看到明显的性能差异,wx 小部件应用程序运行相同,并且 Django 应用程序的性能也几乎相同。

One thing I noticed at work was that the Kaspersky virus scanner tended to slow the python interpreter WAY down. It would take 3-5 seconds for the python prompt to properly appear and 7-10 seconds for Django's test server to fully load. Properly disabling its active scanning brought the start up times back to 0 seconds.

我在工作中注意到的一件事是卡巴斯基病毒扫描程序往往会减慢 python 解释器的速度。python 提示正确出现需要 3-5 秒,Django 的测试服务器完全加载需要 7-10 秒。正确禁用其主动扫描使启动时间回到 0 秒。

回答by Daniel Quinlan

With the OS and network libraries, I can confirm slower performance on Windows, at least for versions =< 2.6.

使用操作系统和网络库,我可以确认 Windows 上的性能较慢,至少对于版本 =< 2.6。

I wrote a CLI podcast-fetcher script which ran great on Ubuntu, but then wouldn't download anything faster than about 80 kB/s (where ~1.6 MB/s is my usual max) on either XP or 7.

我写了一个 CLI podcast-fetcher 脚本,它在 Ubuntu 上运行良好,但在 XP 或 7 上下载的速度不会超过大约 80 kB/s(其中 ~1.6 MB/s 是我通常的最大值)。

I could partially correct this by tweaking the buffer size for download streams, but there was definitely a major bottleneck on Windows, either over the network or IO, that simply wasn't a problem on Linux.

我可以通过调整下载流的缓冲区大小来部分纠正这个问题,但 Windows 上肯定存在一个主要瓶颈,无论是通过网络还是 IO,这在 Linux 上根本不是问题。

Based on this, it seems that system and OS-interfacing tasks are better optimized for *nixes than they are for Windows.

基于此,似乎系统和操作系统接口任务针对 *nixes 的优化比针对 Windows 的优化要好。

回答by Innocuous

Interestingly I ran a direct comparison of a popular Python app on a Windows 10 x64 Machine (low powered admittedly) and a Ubuntu 14.04 VM running on the same machine.

有趣的是,我在 Windows 10 x64 机器(低功耗)和在同一台机器上运行的 Ubuntu 14.04 VM 上运行了一个流行的 Python 应用程序的直接比较。

I have not tested load speeds etc, but am just looking at processor usage between the two. To make the test fair, both were fresh installs and I duplicated a part of my media library and applied the same config in both scenarios. Each test was run independently.

我没有测试加载速度等,但我只是在看两者之间的处理器使用情况。为了使测试公平,两者都是全新安装,我复制了媒体库的一部分并在两种情况下应用了相同的配置。每个测试都是独立运行的。

  • On Windows Python was using 20% of my processor power and it triggered System Compressed Memory to run up at 40% (this is an old machine with 6GB or RAM).
  • With the VM on Ubuntu (linked to my windows file system) the processor usage is about 5% with compressed memory down to about 20%.
  • 在 Windows 上,Python 使用了我 20% 的处理器能力,它触发系统压缩内存以 40% 的速度运行(这是一台具有 6GB 或 RAM 的旧机器)。
  • 使用 Ubuntu 上的 VM(链接到我的 Windows 文件系统),处理器使用率约为 5%,压缩内存降至约 20%。

This is a huge difference. My trigger for running this test was that the app using python was running my CPU up to 100% and failing to operate. I have now been running it in the VM for 2 weeks and my processor usage is down to 65-70% on average. So both on a long and short term test, and taking into account the overhead of running a VM and second operating system, this Python app is significantly faster on Linux. I can also confirm that the Python app responds better, as does everything else on my machine.

这是一个巨大的差异。我运行这个测试的触发器是使用 python 的应用程序运行我的 CPU 高达 100% 并且无法运行。我现在已经在 VM 中运行它 2 周了,我的处理器使用率平均下降到 65-70%。因此,在长期和短期测试中,并考虑到运行虚拟机和第二个操作系统的开销,这个 Python 应用程序在 Linux 上的速度明显更快。我还可以确认 Python 应用程序响应更好,就像我机器上的其他所有内容一样。

Now this could be very application specific, but it is at minimum interesting.

现在这可能是非常特定于应用程序的,但它至少是有趣的。

The PC is an old AMD II X2 X265 Processor, 6GB of RAM, SSD HD (which Python ran from but the VM used a regular 5200rpm HD which gets used for a ton of other stuff including recording of 2 CCTV cameras).

PC 是一个旧的 AMD II X2 X265 处理器,6GB 内存,SSD HD(Python 是从它运行的,但 VM 使用常规的 5200 rpm HD 用于大量其他内容,包括录制 2 个闭路电视摄像机)。