-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.py
More file actions
151 lines (127 loc) · 4.66 KB
/
Copy pathdemo.py
File metadata and controls
151 lines (127 loc) · 4.66 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
from random import choice, randrange
from time import process_time
from lstore.db import Database
from lstore.query import Query
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
END = '\033[0m'
GREEN = '\033[92m'
db = Database()
grades_table = db.create_table('Grades', 5, 0)
query = Query(grades_table)
numtests = 0
numerrors = 0
errors = []
print(f"\n{BOLD}{UNDERLINE}TEST: Insert duplicate key{END}\n")
testname = "Insert duplicate key"
numtests += 1
query.insert(906659671, 0, 0, 0, 0)
if query.insert(906659671, 1, 1, 1, 1):
numerrors += 1
errors.append(testname)
print(f"\n{BOLD}{UNDERLINE}TEST: Insert None value into column{END}\n")
testname = "Insert None value into column"
numtests += 1
if query.insert(906659672, None, 0, 0, 0):
numerrors += 1
errors.append(testname)
print(f"\n{BOLD}{UNDERLINE}TEST: Update nonexistent key{END}\n")
testname = "Update nonexistent key"
numtests += 1
if query.update(906659673, [1, 1, 1, 1, 1]):
numerrors += 1
errors.append(testname)
print(f"{BOLD}{GREEN}Passed {numtests-numerrors} of {numtests} test cases.{END}")
print("Tests failed:")
for e in errors:
print(e)
print(f"\n{BOLD}{UNDERLINE}TEST DATABASE PERFORMANCE 10,000 RECORDS{END}\n")
# Student Id and 4 grades
db = Database()
grades_table = db.create_table('Grades', 5, 0)
query = Query(grades_table)
keys = []
insert_time_0 = process_time()
for i in range(0, 10000):
query.insert(906659671 + i, 93, 0, 0, 0)
keys.append(906659671 + i)
insert_time_1 = process_time()
print(f"{BOLD}Inserting 10k records took:{END} \t\t\t", insert_time_1 - insert_time_0)
# Measuring update Performance
update_cols = [
[None, None, None, None, None],
[None, randrange(0, 100), None, None, None],
[None, None, randrange(0, 100), None, None],
[None, None, None, randrange(0, 100), None],
[None, None, None, None, randrange(0, 100)],
]
update_time_0 = process_time()
for i in range(0, 10000):
query.update(choice(keys), *(choice(update_cols)))
update_time_1 = process_time()
print(f"{BOLD}Updating 10k records took:{END} \t\t\t", update_time_1 - update_time_0)
# Measuring Select Performance
select_time_0 = process_time()
for i in range(0, 10000):
query.select(choice(keys),0 , [1, 1, 1, 1, 1])
select_time_1 = process_time()
print(f"{BOLD}Selecting 10k records took:{END} \t\t\t", select_time_1 - select_time_0)
# Measuring Aggregate Performance
agg_time_0 = process_time()
for i in range(0, 10000, 100):
start_value = 906659671 + i
end_value = start_value + 100
result = query.sum(start_value, end_value - 1, randrange(0, 5))
agg_time_1 = process_time()
print(f"{BOLD}Aggregate 10k of 100 record batch took:{END}\t", agg_time_1 - agg_time_0)
# Measuring Delete Performance
delete_time_0 = process_time()
for i in range(0, 10000):
query.delete(906659671 + i)
delete_time_1 = process_time()
print(f"{BOLD}Deleting 10k records took:{END} \t\t\t", delete_time_1 - delete_time_0)
print(f"\n{BOLD}{UNDERLINE}TEST DATABASE PERFORMANCE 100,000 RECORDS{END}\n")
# Student Id and 4 grades
db = Database()
grades_table = db.create_table('Grades', 5, 0)
query = Query(grades_table)
keys = []
insert_time_0 = process_time()
for i in range(0, 100000):
query.insert(906659671 + i, 93, 0, 0, 0)
keys.append(906659671 + i)
insert_time_1 = process_time()
print(f"{BOLD}Inserting 100k records took:{END} \t\t\t", insert_time_1 - insert_time_0)
# Measuring update Performance
update_cols = [
[None, None, None, None, None],
[None, randrange(0, 100), None, None, None],
[None, None, randrange(0, 100), None, None],
[None, None, None, randrange(0, 100), None],
[None, None, None, None, randrange(0, 100)],
]
update_time_0 = process_time()
for i in range(0, 100000):
query.update(choice(keys), *(choice(update_cols)))
update_time_1 = process_time()
print(f"{BOLD}Updating 100k records took:{END} \t\t\t", update_time_1 - update_time_0)
# Measuring Select Performance
select_time_0 = process_time()
for i in range(0, 100000):
query.select(choice(keys),0 , [1, 1, 1, 1, 1])
select_time_1 = process_time()
print(f"{BOLD}Selecting 100k records took:{END} \t\t\t", select_time_1 - select_time_0)
# Measuring Aggregate Performance
agg_time_0 = process_time()
for i in range(0, 100000, 100):
start_value = 906659671 + i
end_value = start_value + 100
result = query.sum(start_value, end_value - 1, randrange(0, 5))
agg_time_1 = process_time()
print(f"{BOLD}Aggregate 100k of 100 record batch took:{END}\t", agg_time_1 - agg_time_0)
# Measuring Delete Performance
delete_time_0 = process_time()
for i in range(0, 100000):
query.delete(906659671 + i)
delete_time_1 = process_time()
print(f"{BOLD}Deleting 100k records took:{END} \t\t\t", delete_time_1 - delete_time_0)