File tree Expand file tree Collapse file tree
Software Architecture with Python/4Performance Expand file tree Collapse file tree Original file line number Diff line number Diff 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
1414def 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 )
You can’t perform that action at this time.
0 commit comments