-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
66 lines (50 loc) · 2.26 KB
/
index.ts
File metadata and controls
66 lines (50 loc) · 2.26 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
import * as fs from 'fs';
import { ChatbotFlowNavigator, Node, Edge, SearchCriteria } from './algorithm.js';
function benchmarkTypeScript(): any {
// Medición de tiempo para carga de datos
const startLoad = performance.now();
// Cargar datos desde los archivos JSON
const nodesData: Node[] = JSON.parse(fs.readFileSync('data/nodes.json', 'utf-8'));
const edgesData: Edge[] = JSON.parse(fs.readFileSync('data/edges.json', 'utf-8'));
const loadTime = performance.now() - startLoad;
console.log('🚀 TYPESCRIPT BENCHMARK');
console.log(`Cargados ${nodesData.length} nodos y ${edgesData.length} edges`);
console.log(`⏱️ Tiempo de carga de JSON: ${loadTime.toFixed(3)}ms`);
// Medición de tiempo para inicialización
const startInit = performance.now();
const navigator = new ChatbotFlowNavigator(nodesData, edgesData);
const initTime = performance.now() - startInit;
console.log(`⏱️ Tiempo de inicialización: ${initTime.toFixed(3)}ms`);
// Medición de tiempo para búsqueda
const criteria: SearchCriteria = {
button_type: "QUICK_REPLY",
target_contains: "node-GE2H6"
};
// Ejecutar múltiples veces para obtener un promedio más preciso
const iterations = 1000;
let totalSearchTime = 0;
console.log(`🔍 Ejecutando ${iterations} búsquedas para promedio...`);
let nextNode: Node | null = null;
for (let i = 0; i < iterations; i++) {
const startSearch = performance.now();
nextNode = navigator.findNextNode("node-8E70X", criteria);
totalSearchTime += performance.now() - startSearch;
}
const avgSearchTime = totalSearchTime / iterations;
console.log(`⏱️ Tiempo promedio de búsqueda: ${avgSearchTime.toFixed(6)}ms`);
console.log(`⏱️ Tiempo total para ${iterations} búsquedas: ${totalSearchTime.toFixed(3)}ms`);
if (nextNode) {
console.log(`✅ Nodo encontrado: ID = ${nextNode.id}, Tipo = ${nextNode.data.type}`);
} else {
console.log('❌ No se encontró ningún nodo que cumpla los criterios');
}
console.log('\n' + '='.repeat(60) + '\n');
return {
load_time: loadTime,
init_time: initTime,
avg_search_time: avgSearchTime,
total_time: loadTime + initTime + totalSearchTime
};
}
// Ejecutar el benchmark
const results = benchmarkTypeScript();