Why is python so much slower on windows?

对着背影说爱祢 提交于 2019-11-29 03:35:12

I can't answer your question, however consider this list of things that could be making a difference:

  • 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.

  • Your VM might be timing inaccurately.

  • You're linking different implementations of Python's dependencies, notably libc as Ignacio Vazquez-Abrams points out.

  • 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.

Had similar problem on windows 10 - it was because of windows defender.

I had to exclude python directories and process in windows defender settings and restart computer.

Before: I had to wait like ~20 seconds to run any python code - now it's milliseconds.

Do you run antivirus software on that Windows box? This perhaps could explain it. I personally like to add Python, Cygwin and my sources directory to antivirus exclusion list - I think I get a small, but noticeable speedup. Maybe that explains your results.

Benchmark your startup, but there are just simply some slow modules to initialize on windows. A tiny hack that saves me a second on startup every time:

import os
import mimetypes #mimetypes gets imported later in dep chain

if __name__ == "__main__":
   # stub this out, so registry db wont ever be read, not needed
   mimetypes._winreg = None

Another source of slowness is, multiple standard library modules compile and cache their regexes at import time. re.compile just looks like its slow on windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!