-
-
Save pfmoore/a5406e0901609ed08cab8a0719d4e866 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tempfile import TemporaryDirectory | |
import os | |
import time | |
import datetime | |
import venv | |
import subprocess | |
import sys | |
def mkvenvs(venv_type="dummy", N=100): | |
def do_nothing(target): | |
pass | |
def with_venv(target): | |
builder = venv.EnvBuilder() | |
builder.create(target) | |
def with_venv_sp(target): | |
subprocess.run([sys.executable, "-m", "venv", "--without-pip", target]) | |
def with_uv(target): | |
subprocess.run(["uv", "venv", "--quiet", target]) | |
if venv_type == "dummy": | |
mk_venv = do_nothing | |
elif venv_type == "venv": | |
mk_venv = with_venv | |
elif venv_type == "venv_sp": | |
mk_venv = with_venv_sp | |
elif venv_type == "uv": | |
mk_venv = with_uv | |
with TemporaryDirectory() as tmp: | |
total_duration = datetime.timedelta(0) | |
for i in range(N): | |
target = os.path.join(tmp, f"venv_{i}") | |
start = datetime.datetime.now() | |
mk_venv(target) | |
end = datetime.datetime.now() | |
total_duration += end - start | |
print(f"Average creation time ({venv_type}): {total_duration / N}") | |
mkvenvs("dummy") | |
mkvenvs("venv") | |
mkvenvs("venv_sp") | |
mkvenvs("uv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment