-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsets_v_lists.py
More file actions
30 lines (25 loc) · 899 Bytes
/
Copy pathsets_v_lists.py
File metadata and controls
30 lines (25 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python3
"""
Create both a set and a list, each containing the first 1,000 perfect squares.
Performs searches both data structures for, and do nothing with all the
integers from 0 to 999,999.
Report the time required for the efforts
"""
from time import clock
data_struct_size = 1000
big_set = {x ** 2 for x in range(data_struct_size)}
big_list = [x ** 2 for x in range(data_struct_size)]
search_size = 1000000
print('VERIFY\nSet:\v{0}\nList:\v{1}'.format(type(big_set), type(big_list)))
start_time = clock()
for search_item in range(search_size):
if search_item in big_set:
pass
stop_time = clock()
print('Set Search - Elapsed Time: {0}'.format(stop_time - start_time))
start_time = clock()
for search_item in range(search_size):
if search_item in big_list:
pass
stop_time = clock()
print('List Search Elapsed Time: {0}'.format(stop_time - start_time))