-
-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathbenchmark_search.ts
More file actions
77 lines (64 loc) · 2.38 KB
/
benchmark_search.ts
File metadata and controls
77 lines (64 loc) · 2.38 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
70
71
72
73
74
75
76
77
import { PolymarketExchange } from './src/exchanges/polymarket';
import { KalshiExchange } from './src/exchanges/kalshi';
import { LimitlessExchange } from './src/exchanges/limitless';
import { performance } from 'perf_hooks';
// Search term for the benchmark
const SEARCH_TERM = "BTC";
async function runBenchmark() {
console.log(`Starting Search Benchmark for term: "${SEARCH_TERM}"`);
console.log(`====================================================\n`);
const exchanges = [
new PolymarketExchange(),
new KalshiExchange(),
new LimitlessExchange()
];
const statuses = ['active', 'inactive', 'closed', 'all'] as const;
const results: any[] = [];
for (const exchange of exchanges) {
console.log(`Testing ${exchange.name}...`);
for (const status of statuses) {
process.stdout.write(` - Status: ${status.padEnd(8)} ... `);
const start = performance.now();
let count = 0;
let error = null;
try {
const events = await exchange.fetchEvents({
query: SEARCH_TERM,
status: status,
limit: 10000
});
count = events.length;
} catch (e: any) {
error = e.message;
}
const end = performance.now();
const duration = Math.round(end - start);
results.push({
Exchange: exchange.name,
Status: status,
Results: error ? 'ERROR' : count,
'Time (ms)': duration,
Message: error || ''
});
console.log(`${error ? 'FAIL' : 'DONE'} in ${duration}ms (${count} results)`);
}
console.log(''); // Newline between exchanges
}
console.log('\n--- FINAL BENCHMARK SUMMARY ---');
console.table(results.map(r => ({
Exchange: r.Exchange,
Status: r.Status,
Results: r.Results,
'Time (ms)': r['Time (ms)']
})));
// Print errors if any
const errors = results.filter(r => r.Message);
if (errors.length > 0) {
console.log('\n--- ERROR DETAILS ---');
errors.forEach(e => console.log(`[${e.Exchange} - ${e.Status}]: ${e.Message}`));
}
}
runBenchmark().catch(error => {
console.error('\nBenchmark failed with critical error:');
console.error(error);
});