-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_test.py
100 lines (86 loc) · 3.19 KB
/
map_test.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from MoonMap_memory import MoonMap
from datetime import datetime
from collections import OrderedDict
import matplotlib.pyplot as plt
def test(size, fill):
"""using for loops this method sets, loads, gets and deletes data"""
map = MoonMap(size)
__test_set(fill, map)
__test_load(map)
__test_get(fill, map)
__test_delete(fill, map)
__test_load(map)
def __test_set(fill, memap):
"""sets Map with values from 0 to the fill value"""
x = datetime.now()
for i in range(fill):
memap.boolean_set(("yumm" + str(i)), i)
y = datetime.now()
sec = (y - x).total_seconds()
sec_per_set = sec / fill
micsec = sec_per_set * 1000000
print("It took {} microseconds to set values set in {} seconds".format(fill, micsec))
return micsec
def __test_delete(fill, memap):
"""Enter the number of values to delete from MoonMap, values are deleted in a loop starting from zero
to the fill value"""
x = datetime.now()
for i in range(fill):
memap.delete(("yumm" + str(i)))
y = datetime.now()
sec = (y - x).total_seconds()
sec_per_delete = sec/fill
micsec = sec_per_delete * 1000000
print("It took an average time of {} to delete each item from the map".format(micsec))
return micsec
def __test_get(fill, memap):
"""Retrieves values from 0 to the fill value"""
x = datetime.now()
for i in range(fill):
memap.delete(("yumm" + str(i)))
y = datetime.now()
sec = ( (y - x).total_seconds() )
sec = (y - x).total_seconds()
sec_per_get = sec / fill
micsec = sec_per_get * 1000000
print("Toook an average of {} microseconds to get each item".format(micsec))
return micsec
def __test_load(memap):
"""Finds the the time it took to calculate load in microseconds (usually ZERO)"""
x = datetime.now()
for i in range(1000):
memap.load()
y = datetime.now()
sec = (y - x).total_seconds()
sec_per_load = sec / 1000
micsec = sec_per_delete * 1000000
print("Load is {}, it took {} microseconds to load".format(memap.load(), micsec))
return micsec
###EXTRA METHODS TO VISUALIZE efficency, NOT NEEDED FOR TESTING
def run_time_graph(size):
"""NOT NEEDED FOR TESTING
This Method was used to generate scatter plots that showed algorythm efficency for setting,
retrieving and deleting values from a MoonMap with size 1000"""
map = MoonMap(size)
set = OrderedDict()
get = OrderedDict()
delete = OrderedDict()
for i in range(200, size):
set[i] = ( __test_set(i, map)/float(i) ) * 1000000
get[i] = (__test_get(i, map)/float(i) ) * 1000000
delete[i] = (__test_delete(i, map)/float(i) ) * 1000000
print(i)
__plot(set, "Set Speed (Map Size {})".format(size))
__plot(get, "Get Speed (Map Size {})".format(size) )
__plot(delete, "Delete Speed (Map Size {})".format(size))
def __plot( dict1, title):
"""Used to plot and format graphs"""
plt.title(title)
plt.xlabel("Run Time (microsecondsS)")
plt.ylabel("Number of Items Retreived")
plt.ylim(0, max(dict1.values()))
plt.xlim(min(dict1.keys()), max(dict1.keys()) )
x1, y1 = zip(*dict1.items())
plt.scatter(x1, y1)
plt.show()
#run_time_graph(1000)