-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for map and for future shared-memory map
- Loading branch information
1 parent
e22d045
commit 738232a
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import easy_multip | ||
import time | ||
import random | ||
import sys | ||
sys.path.insert(1, '..') | ||
|
||
args = [(1,2), (3,5), (6,2), (7,0), (7,1), (8,5), (5,2), (8,8), (4,7), (1,6), (1,1), (2,2), (6,6), (7,4), (7,3), (5,5)] | ||
|
||
def test_func(arg_tup): | ||
x, y, ref_data = arg_tup | ||
time.sleep(random.random() * 2) | ||
return x + y + ref_data[5] | ||
|
||
def test_func2(arg_tup, shared_mem): | ||
x, y = arg_tup | ||
time.sleep(random.random() * 2) | ||
return x + y + shared_mem[5] | ||
|
||
|
||
if __name__ == '__main__': | ||
REF_DATA = [5 for _ in range(10 ** 8)] | ||
|
||
t0 = time.time() | ||
data1 = [test_func((*arg, REF_DATA)) for arg in args] | ||
print(f'Normal loop time: {round(time.time() - t0, 2)}') | ||
|
||
t0 = time.time() | ||
data2 = easy_multip.map(test_func, [(*arg, REF_DATA) for arg in args]) | ||
print(f'easy_multip.doloop time: {round(time.time() - t0, 2)}') | ||
|
||
t0 = time.time() | ||
data3 = easy_multip.map(test_func2, [(arg) for arg in args], shared_memory_iterable=REF_DATA) | ||
print(f'easy_multip.doloop time: {round(time.time() - t0, 2)}') | ||
|
||
print(f'data1 == data2 == data3 check: {data1 == data2 == data3}') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import easy_multip | ||
import time | ||
import random | ||
import sys | ||
sys.path.insert(1, '..') | ||
|
||
args = [(1,2), (3,5), (6,2), (7,0), (7,1), (8,5), (5,2), (8,8), (4,7), (1,6), (1,1), (2,2), (6,6), (7,4), (7,3), (5,5)] | ||
|
||
def test_func(arg_tup): | ||
x, y = arg_tup | ||
time.sleep(random.random() * 2) | ||
return x + y | ||
|
||
|
||
if __name__ == '__main__': | ||
t0 = time.time() | ||
data1 = [test_func(arg) for arg in args] | ||
print(f'Normal loop time: {round(time.time() - t0, 2)}') | ||
|
||
t0 = time.time() | ||
data2 = easy_multip.map(test_func, args) | ||
print(f'easy_multip.doloop time: {round(time.time() - t0, 2)}') | ||
|
||
print(f'data1 == data2 check: {data1 == data2}') |