2024-05-29 02:29:36 +02:00
|
|
|
import json
|
|
|
|
from typing import Callable, Optional
|
|
|
|
from typing_extensions import Dict
|
|
|
|
import time
|
|
|
|
|
|
|
|
from models.data_thread import Data_Thread, Threads
|
|
|
|
|
|
|
|
def time_func(name: str, function_name: str, x : Callable, repeat : Optional[int] = None) -> Dict[str, float]:
|
|
|
|
if (not repeat):
|
|
|
|
a = time.perf_counter()
|
|
|
|
r = x()
|
|
|
|
timed = time.perf_counter()-a
|
|
|
|
print(f"{name} took {timed:.3f}s")
|
|
|
|
if r: print(f"|> {r}")
|
|
|
|
return {function_name: timed}
|
|
|
|
|
|
|
|
else:
|
|
|
|
timings = []
|
|
|
|
for _ in range(repeat):
|
|
|
|
a = time.perf_counter()
|
|
|
|
r = x()
|
|
|
|
timings.append(time.perf_counter()-a)
|
|
|
|
print(f"{name} took in average {sum(timings)/len(timings):.3f}s over {repeat} runs")
|
|
|
|
if r: print(f"|> {r}")
|
|
|
|
return {function_name: sum(timings)/len(timings)}
|
|
|
|
|
|
|
|
|
2024-06-02 23:23:02 +02:00
|
|
|
def preprocess_json(multiplicator: int):
|
2024-06-01 17:28:13 +02:00
|
|
|
# Change for more or less values
|
2024-06-02 23:23:02 +02:00
|
|
|
for x in range(0, multiplicator):
|
2024-05-31 15:53:07 +02:00
|
|
|
with open('data.json', 'r') as f:
|
|
|
|
data : dict = json.load(f)
|
|
|
|
for d in data:
|
|
|
|
x = Data_Thread()
|
|
|
|
for k in d.keys():
|
|
|
|
x.__setattr__(k, d[k])
|
2024-06-01 17:12:31 +02:00
|
|
|
Threads.append(x)
|