Why is python so much slower on windows?

前端 未结 4 2026
感情败类
感情败类 2020-12-16 13:00

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

相关标签:
4条回答
  • 2020-12-16 13:36

    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.

    0 讨论(0)
  • 2020-12-16 13:36

    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.

    0 讨论(0)
  • 2020-12-16 13:47

    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.

    0 讨论(0)
  • 2020-12-16 13:48

    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

    0 讨论(0)
提交回复
热议问题