33 lines
811 B
Python
33 lines
811 B
Python
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):
|
|
...
|