summaryrefslogtreecommitdiff
path: root/tests/parallelize_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/parallelize_test.py')
-rwxr-xr-xtests/parallelize_test.py30
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)