Python slow to start on Windows

Viewed 1029

I noticed my Python code always takes longer to run on Windows than it does on Mac. Is there some way to improve this? The Windows machine is very powerful so I don't think it's a hardware issue (36 core Xeon, 96GB RAM, SSD). Python versions are similar, I'm running 3.7.9 on Windows 10, and 3.7.7 on MacOS Mojave.
For example, a simple print statement takes 7 times longer. Checking the version takes 12 times longer.
I uninstalled all pip modules on Windows.

I'm trying to write some very lightweight scripts where fast runtime is important.

$ time python3 -c "print('hello world')"
hello world

real    0m0.030s
user    0m0.019s
sys     0m0.009s

$ time python3 --version
Python 3.7.7

real    0m0.015s
user    0m0.003s
sys     0m0.005s

And on Windows 10 Powershell:

(Measure-Command {python -c "print('hello world')"}).TotalSeconds
0.2249363
(Measure-Command {python --version}).TotalSeconds
0.1776381

Edit: I captured the events with SysInternals Process Monitor and it shows 11,222 events for a single invocation of python --version. Wow, no wonder it takes so long! Unfortunately this doesn't really explain it, because it shows 0.233 seconds delay between "Thread Create" and Load Image".

enter image description here

0 Answers
Related