diff options
| author | Scott Gasch <[email protected]> | 2021-09-07 22:20:40 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2021-09-07 22:20:40 -0700 |
| commit | b10d30a46e601c9ee1f843241f2d69a1f90f7a94 (patch) | |
| tree | 30c95e6f4333b57ff3ae7a4dee278b2097612d10 /tests/parallelize_test.py | |
| parent | f49bb9db0c6d1a8622dca1717db68462a4209112 (diff) | |
Various changes.
Diffstat (limited to 'tests/parallelize_test.py')
| -rwxr-xr-x | tests/parallelize_test.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/parallelize_test.py b/tests/parallelize_test.py index 44f723c..d87b5e7 100755 --- a/tests/parallelize_test.py +++ b/tests/parallelize_test.py @@ -8,6 +8,23 @@ import parallelize as p import decorator_utils import executors import math_utils +import smart_future + + [email protected](method=p.Method.THREAD) +def compute_factorial_thread(n): + total = 1 + for x in range(2, n): + total *= x + return total + + [email protected](method=p.Method.PROCESS) +def compute_factorial_process(n): + total = 1 + for x in range(2, n): + total *= x + return total @p.parallelize(method=p.Method.REMOTE) @@ -21,6 +38,19 @@ def list_primes(n): @decorator_utils.timed def driver() -> None: + results = [] + for _ in range(20): + results.append(compute_factorial_process(_)) + for future in smart_future.wait_any(results): + print(f'Process: {future}') + + results = [] + for _ in range(20): + results.append(compute_factorial_thread(_)) + smart_future.wait_all(results) + for future in results: + print(f'Thread: {future}') + results = {} for _ in range(50): n = random.randint(0, 100000) |
