Example #1
0
from src.db import Database
from src.query import Query
from time import process_time
from random import choice, randrange

# Student Id and 4 grades
db = Database()
grades_table = db.create_table('Grades', 0, 5)
query = Query(grades_table)
keys = []

# Measuring Insert Performance
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("Inserting 10k records took:  \t\t\t", insert_time_1 - insert_time_0)

# Measuring update Performance
update_cols = [
    [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), None],
    [None, None, None, None, randrange(0, 100)],
]

update_time_0 = process_time()
for i in range(0, 10000):
Example #2
0
records = {}

seed(3562901)

for i in range(0, 1000):
    key = 92106429 + randint(0, 9000)
    while key in records:
        key = 92106429 + randint(0, 9000)
    records[key] = [
        key,
        randint(0, 20),
        randint(0, 20),
        randint(0, 20),
        randint(0, 20)
    ]
    query.insert(*records[key])
    print('inserted', records[key])

for key in records:
    record = query.select(key, [1, 1, 1, 1, 1])[0]
    error = False
    for i, column in enumerate(record.columns):
        if column != records[key][i]:
            error = True
    if error:
        print('select error on', key, ':', record, ', correct:', records[key])
    else:
        print('select on', key, ':', record)

for key in records:
    updated_columns = [None, None, None, None, None]
Example #3
0
from src.query import Query
from src.table import Table
from src.bits import Bits
table = Table("test", 5, 0)

query = Query(table)
# record1 = [1, 90, 0, 0, 0]
# record2 = [2, 91, 0, 0, 0]
# record3 = [3, 92, 0, 0, 0]
query.insert(1, 90, 0, 0, 0)
query.insert(2, 91, 0, 0, 0)
query.insert(3, 92, 0, 0, 0)

r1 = table.get(1, Bits('11111'))
r2 = table.get(2, Bits('11111'))
r3 = table.get(3, Bits('11111'))
print(r1)
print(r2)
print(r3)

query.delete(1)
query.delete(2)
print("record3's LID: ", table.key_lid[3])
db = Database()
db.open('~/ECS165')
grades_table = db.create_table('Grades', 5, 0)

keys = []
records = {}
num_threads = 2
seed(8739878934)

# Generate random records
for i in range(0, 10000):
    key = 92106429 + i
    keys.append(key)
    records[key] = [key, 0, 0, 0, 0]
    q = Query(grades_table)
    q.insert(None, False, False, *records[key])

# create TransactionWorkers
transaction_workers = []
for i in range(num_threads):
    transaction_workers.append(TransactionWorker([]))

# generates 10k random transactions
# each transaction will increment the first column of a record 5 times
for i in range(1000):
    k = randint(0, 2000 - 1)
    transaction = Transaction()
    for j in range(5):
        key = keys[k * 5 + j]
        q = Query(grades_table)
        transaction.add_query(q.select, key, 0, [1, 1, 1, 1, 1])