71 lines
2.7 KiB
Python
71 lines
2.7 KiB
Python
|
from typing import Generic, TypeVar
|
||
|
from typing_extensions import Dict
|
||
|
from abc import abstractmethod
|
||
|
from utils.utils import time_func
|
||
|
from time import sleep
|
||
|
|
||
|
T = TypeVar('T')
|
||
|
NUM_RUNS = 10000
|
||
|
|
||
|
class DB_Testing(Generic[T]):
|
||
|
driver_name: str
|
||
|
|
||
|
@abstractmethod
|
||
|
def __init__(self) -> None:
|
||
|
pass
|
||
|
|
||
|
@abstractmethod
|
||
|
def delete_table(self, driver: T):
|
||
|
pass
|
||
|
|
||
|
@abstractmethod
|
||
|
def create_table(self, driver: T):
|
||
|
pass
|
||
|
|
||
|
@abstractmethod
|
||
|
def delete_data(self, driver: T):
|
||
|
pass
|
||
|
|
||
|
@abstractmethod
|
||
|
def add_bulk(self, driver: T):
|
||
|
pass
|
||
|
|
||
|
@abstractmethod
|
||
|
def add_singles(self, driver: T):
|
||
|
pass
|
||
|
|
||
|
@abstractmethod
|
||
|
def attach5_mr_mrs(self, driver: T) -> str:
|
||
|
pass
|
||
|
|
||
|
@abstractmethod
|
||
|
def search_mails_ends_microsoftcom(self, driver: T) -> str:
|
||
|
pass
|
||
|
|
||
|
@abstractmethod
|
||
|
def search_lorem(self, driver: T) -> str:
|
||
|
pass
|
||
|
|
||
|
@abstractmethod
|
||
|
def get_sum_attachment_less_5(self, driver: T) -> str:
|
||
|
pass
|
||
|
|
||
|
|
||
|
def do_tests(self, driver: T) -> Dict[str, float]:
|
||
|
stats = {}
|
||
|
print(f"\n### Starting {self.driver_name} Benchmark ###")
|
||
|
stats.update(time_func(f"[{self.driver_name}] Reset table", "delete_table", lambda : self.delete_table(driver)))
|
||
|
stats.update(time_func(f"[{self.driver_name}] Create table", "create_table", lambda : self.create_table(driver)))
|
||
|
stats.update(time_func(f"[{self.driver_name}] Add singles", "add_singles", lambda : self.add_singles(driver)))
|
||
|
stats.update(time_func(f"[{self.driver_name}] Delete data", "delete_data", lambda : self.delete_data(driver)))
|
||
|
stats.update(time_func(f"[{self.driver_name}] Add bulk", "add_bulk", lambda : self.add_bulk(driver)))
|
||
|
|
||
|
sleep(1) # To wait for any indexing to avoid race conditions somehow
|
||
|
|
||
|
# Multiple
|
||
|
stats.update(time_func(f"[{self.driver_name}] Count mails with more than 5 attachments and Mr/Mrs", "attach5_mr_mrs", lambda : self.attach5_mr_mrs(driver), NUM_RUNS))
|
||
|
stats.update(time_func(f"[{self.driver_name}] Sum the number of attachment from mail that have less than 5 attachments", "get_sum_attachment_less_5", lambda : self.get_sum_attachment_less_5(driver), NUM_RUNS))
|
||
|
stats.update(time_func(f"[{self.driver_name}] Count mails that have a lorem sentence", "search_lorem", lambda : self.search_lorem(driver), NUM_RUNS))
|
||
|
stats.update(time_func(f"[{self.driver_name}] Count mails that have a mail that ends with microsoft.com", "search_mails_ends_microsoftcom", lambda : self.search_mails_ends_microsoftcom(driver), NUM_RUNS))
|
||
|
print("\n")
|
||
|
return stats
|