Why is python so much slower on windows?

前端 未结 4 2057
感情败类
感情败类 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: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

提交回复
热议问题