2026-rff_mp/MusinAA/task1/util/timeTester.py

24 lines
914 B
Python
Raw Normal View History

2026-03-30 14:47:24 +00:00
import time
from typing import Callable, Any
def _concrete_insert_tester(func: Callable[[Any, str, str], Any], records: list) -> float:
"""Исследует время работы функции вставки"""
aboba = None
start = time.perf_counter()
for item in records:
aboba = func(aboba, name=item[0], phone=item[1])
end = time.perf_counter()
elapsed = end - start
return elapsed
def insert_tester(func_to_test: Callable[[Any, str, str], Any], records_shuffled, records_sorted) -> dict:
"""Возвращает словарь с временем сортировки в обоих режимах"""
shuffled = _concrete_insert_tester(func_to_test, records_shuffled)
sorted = _concrete_insert_tester(func_to_test, records_sorted)
return {"Function": func_to_test.__name__,
"shuffled": shuffled,
"sorted": sorted
}