-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_dict.py
More file actions
38 lines (34 loc) · 764 Bytes
/
Copy pathtest_dict.py
File metadata and controls
38 lines (34 loc) · 764 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
30
31
32
33
34
35
36
37
38
#! /usr/bin/env python
import random, time
def strTest():
hashmap = {}
print("Setting")
for k in dir(str):
hashmap[k] = k
print("Getting")
for k in dir(str):
if hashmap[k] != k:
print("Error with data: "+str(k))
def randTest():
random.seed(1993)
N = 15000000
hashmap = {}
values = []
print("Inserting")
start = time.time()
for i in range(0, N):
value = i*10 + random.randrange(0, 10)
values.append(value)
hashmap[value] = value
end = time.time()
print("Time: %f"%(end-start))
print("Searching")
start = time.time()
for i in range(0, N):
if hashmap[values[i]] != values[i]:
print("ERROR: could not find key "+str(values[i]))
end = time.time()
print("Time: %f"%(end-start))
if __name__ == "__main__":
#strTest()
randTest()