2026-rff_mp/MusinAA/task1/util/timeTester.py
2026-03-30 17:47:24 +03:00

24 lines
914 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}