-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.py
More file actions
69 lines (50 loc) · 2.18 KB
/
index.py
File metadata and controls
69 lines (50 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import json
import time
from algorith import ChatbotFlowNavigator
def benchmark_python():
# Medición de tiempo para carga de datos
start_time = time.perf_counter()
# Cargar datos desde los archivos JSON
with open("data/nodes.json", "r", encoding="utf-8") as f:
nodes_data = json.load(f)
with open("data/edges.json", "r", encoding="utf-8") as f:
edges_data = json.load(f)
load_time = (time.perf_counter() - start_time) * 1000 # Convertir a ms
print(f"🐍 PYTHON BENCHMARK")
print(f"Cargados {len(nodes_data)} nodos y {len(edges_data)} edges")
print(f"⏱️ Tiempo de carga de JSON: {load_time:.3f}ms")
# Medición de tiempo para inicialización
start_time = time.perf_counter()
navigator = ChatbotFlowNavigator(nodes_data, edges_data)
init_time = (time.perf_counter() - start_time) * 1000
print(f"⏱️ Tiempo de inicialización: {init_time:.3f}ms")
# Medición de tiempo para búsqueda
criteria = {"button_type": "QUICK_REPLY", "target_contains": "node-GE2H6"}
# Ejecutar múltiples veces para obtener un promedio más preciso
iterations = 1000
total_search_time = 0
print(f"🔍 Ejecutando {iterations} búsquedas para promedio...")
for _ in range(iterations):
start_time = time.perf_counter()
next_node = navigator.find_next_node("node-8E70X", criteria)
total_search_time += time.perf_counter() - start_time
avg_search_time = (total_search_time / iterations) * 1000
print(f"⏱️ Tiempo promedio de búsqueda: {avg_search_time:.6f}ms")
print(
f"⏱️ Tiempo total para {iterations} búsquedas: {total_search_time * 1000:.3f}ms"
)
if next_node:
print(
f"✅ Nodo encontrado: ID = {next_node['id']}, Tipo = {next_node['data']['type']}"
)
else:
print("❌ No se encontró ningún nodo que cumpla los criterios")
print("\n" + "=" * 60 + "\n")
return {
"load_time": load_time,
"init_time": init_time,
"avg_search_time": avg_search_time,
"total_time": load_time + init_time + (total_search_time * 1000),
}
if __name__ == "__main__":
python_results = benchmark_python()