m2-traitement-benchmark/interfaces/db_testing_interface.py

87 lines
3.2 KiB
Python
Raw Normal View History

2024-05-29 02:29:36 +02:00
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')
2024-05-31 15:53:07 +02:00
NUM_RUNS = 100
2024-05-29 02:29:36 +02:00
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
2024-05-31 02:04:24 +02:00
@abstractmethod
2024-05-31 02:40:35 +02:00
def update_add_replies_per_last_name(self, driver: T):
2024-05-31 02:04:24 +02:00
pass
2024-05-31 02:40:35 +02:00
@abstractmethod
def update_add_replies_per_subject(self, driver: T):
pass
2024-05-29 02:29:36 +02:00
def do_tests(self, driver: T) -> Dict[str, float]:
stats = {}
print(f"\n### Starting {self.driver_name} Benchmark ###")
2024-05-31 15:53:07 +02:00
self.delete_table(driver)
self.create_table(driver)
2024-05-29 02:29:36 +02:00
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
2024-05-31 02:04:24 +02:00
# Search
2024-05-29 02:29:36 +02:00
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))
2024-05-31 02:04:24 +02:00
# Update
stats.update(time_func(f"[{self.driver_name}] Update all thread to add a field with the total replies per last name", "update_add_replies_per_last_name", lambda : self.update_add_replies_per_last_name(driver), NUM_RUNS))
2024-05-31 02:40:35 +02:00
stats.update(time_func(f"[{self.driver_name}] Update all thread to add a field with the total replies per subject", "update_add_replies_per_subject", lambda : self.update_add_replies_per_subject(driver), NUM_RUNS))
2024-05-31 02:04:24 +02:00
2024-05-29 02:29:36 +02:00
print("\n")
2024-05-31 15:53:07 +02:00
return stats