Pydantic benchmark

This commit is contained in:
Eden Kirin
2023-10-11 20:33:21 +02:00
commit 3e02a67d94
13 changed files with 553 additions and 0 deletions

32
benchmark/base.py Normal file
View File

@ -0,0 +1,32 @@
from abc import ABC, abstractmethod
from pathlib import Path
import time
class BenchmarkBase(ABC):
def __init__(self, test_file_name: Path) -> None:
self.test_file_name = test_file_name
def _read_test_file(self) -> str:
with open(self.test_file_name, "r") as f:
return f.read()
def start_timer(self) -> None:
self.__timer = time.perf_counter()
def stop_timer(self) -> float:
return time.perf_counter() - self.__timer
def execute(self) -> float:
print(f"*** Running {self.__class__.__name__}")
self.start_timer()
self._benchmark()
benchmark_time = self.stop_timer()
print(f"Finished in {benchmark_time:0.3f}s")
return benchmark_time
@abstractmethod
def _benchmark(self):
...