Skip to content

Commit d5823b4

Browse files
committed
i0
1 parent be8edb0 commit d5823b4

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

Software Architecture with Python/4Performance/i0common_items.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def setup(n):
1010
a1 = random.sample(range(0, 2*n), n)
1111
a2 = random.sample(range(0, 2*n), n)
1212

13-
contextmanager
13+
@contextmanager
1414
def timer():
1515
try:
1616
start = timer_func()
@@ -44,4 +44,19 @@ def common_items_v2(seq1, seq2):
4444
except KeyError:
4545
pass
4646

47-
return [item[0] for item in seq_dict1.items() if item[1]>1]
47+
return [item[0] for item in seq_dict1.items() if item[1]>1]
48+
49+
50+
def test(n, func):
51+
""" Generate test data and perform test on a given function """
52+
53+
a1=random.sample(range(0, 2*n), n)
54+
a2=random.sample(range(0, 2*n), n)
55+
56+
with timer() as t:
57+
result = func(a1, a2)
58+
59+
if __name__ == "__main__":
60+
import sys
61+
test(int(sys.argv[1]), common_items_v1)
62+
test(int(sys.argv[1]), common_items_v2)

0 commit comments

Comments
 (0)