Background
Hello. We write python code that gets run on servers we don't control. We don't know very much about the environment the code gets run in. Our code gets rejected if it takes more than 3 seconds to run. So I decided to start timing our code using a virtual environment, to give a worst-case scenario runtime estimate.
Question
I was surprised to find that in a fresh virtual environment, it takes 5 seconds just to import numpy. Can someone explain why that would be? Is there some trick to speed it up? It seems prohibitive for a basic library to be that slow.
Steps to reproduce:
rm -r /tmp/envvirtualenv /tmp/env/tmp/env/bin/pip install numpytime /tmp/env/bin/python3 -c 'import numpy'
On my high-end laptop it returns
real 0m5.534s
user 0m0.612s
sys 0m0.133s
Note that, for reasons that are not clear to me, if you repeat the step #4 without going back to step #1, the time is significantly less. This persists even if you run, say, find /tmp -type d -name '__pycache__' -exec rm -r {} \; first. It must be some other type of module caching that I don't know about? Anyway, it doesn't matter for my purposes, because I can't control the cache state of the remote servers.