Last active
January 3, 2021 12:46
-
-
Save peterbe/ce8d4e25ae43b7063c0b16b46c21bb2f to your computer and use it in GitHub Desktop.
Context for this is this blog post: https://www.peterbe.com/plog/ideal-number-of-workers-in-jest-maxWorkers
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
import time | |
import subprocess | |
times = {} | |
def fmt(s): | |
return f'{s:.2f}s' | |
def test(workers): | |
cmd = f'yarn run test --maxWorkers={workers}' | |
print(cmd) | |
if workers not in times: | |
times[workers] = [] | |
t0 = time.time() | |
output = subprocess.run(cmd, shell=True, check=True) | |
t1 = time.time() | |
assert not output.returncode | |
times[workers].append(t1 - t0) | |
import random | |
workers = list(range(1, 9)) * 4 | |
random.shuffle(workers) | |
for worker in workers: | |
test(worker) | |
import statistics | |
for workers in sorted(times): | |
these = times[workers] | |
print("WORKERS:", workers) | |
print("BEST :", fmt(min(these))) | |
print("MEDIAN :", fmt(statistics.median(these))) | |
print() | |
print("SORTED BY BEST TIME:") | |
bests = [] | |
for workers in times: | |
best = min(times[workers]) | |
bests.append((best, workers)) | |
bests.sort() | |
for seconds, workers in bests: | |
print(workers, fmt(seconds)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run it like this:
...and wait.
My output became: