Skip to content

Commit

Permalink
timing
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Oct 11, 2024
1 parent 17dd6bc commit 6e265b3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion mypy_primer/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def parse_options(argv: list[str]) -> _Args:
primer_group.add_argument(
"-j",
"--concurrency",
default=multiprocessing.cpu_count(),
default=multiprocessing.cpu_count() - 8,
type=int,
help="number of subprocesses to use at a time",
)
Expand Down
23 changes: 14 additions & 9 deletions mypy_primer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,23 @@ async def inner(project: Project) -> tuple[float, Project]:
result = await project.run_typechecker(type_checker_exe, typeshed_dir=None)
return (result.runtime, project)

projects = select_projects()
results = []
for fut in asyncio.as_completed([inner(project) for project in projects]):
time_taken, project = await fut
results.append((time_taken, project))
print(f"[{len(results)}/{len(projects)}] {time_taken:6.2f}s {project.location}")
import collections, statistics, random

results.sort(reverse=True)
projects = select_projects()
results = collections.defaultdict(list)
for _ in range(5):
random.shuffle(projects)
for i, fut in enumerate(asyncio.as_completed([inner(project) for project in projects])):
time_taken, project = await fut
results[project.location].append(time_taken)
print(f"[{i}/{len(projects)}] {time_taken:6.2f}s {project.location}")

results = [(statistics.mean(times), location) for location, times in results.items()]
results.sort(key=lambda x: x[0], reverse=True)
print("\n" * 5)
print("Results:")
for time_taken, project in results:
print(f"{time_taken:6.2f}s {project.location}")
for time_taken, location in results:
print(f"{time_taken:6.2f}s {location}")


# ==============================
Expand Down
20 changes: 11 additions & 9 deletions mypy_primer/type_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,21 @@ async def pip_install(*targets: str) -> None:
repo_dir = await ensure_repo_at_revision(repo, mypy_dir, revision_like)
if mypyc_compile_level is not None:
env = os.environ.copy()
env["MYPYC_OPT_LEVEL"] = str(mypyc_compile_level)
await pip_install("typing_extensions", "mypy_extensions")
env["MYPY_USE_MYPYC"] = "1"
env["MYPYC_OPT_LEVEL"] = str(mypyc_compile_level) # can be zero
await pip_install("typing_extensions", "mypy_extensions", "tomli", "types-psutil", "types-setuptools")
await run(
[str(venv.python), "setup.py", "--use-mypyc", "build_ext", "--inplace"],
[str(venv.python), "-m", "pip", "install", ".", "--no-build-isolation"],
cwd=repo_dir,
env=env,
)
targets = []
if editable:
targets.append("--editable")
targets.append(str(repo_dir))
targets.append("tomli")
await pip_install(*targets)
else:
targets = []
if editable:
targets.append("--editable")
targets.append(str(repo_dir))
targets.append("tomli")
await pip_install(*targets)

with open(venv.site_packages / "primer_plugin.pth", "w") as f:
# pth file that lets us let mypy import plugins from another venv
Expand Down

0 comments on commit 6e265b3

Please sign in to comment.