This repository has been archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
61 lines (53 loc) · 1.51 KB
/
test.js
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
const axios = require('axios');
/*
testing rpc letancy/speed and responds
*/
async function testRPC(url) {
try {
const startTime = Date.now();
await axios.get(url);
const endTime = Date.now();
const latency = endTime - startTime;
return latency;
} catch (error) {
console.error(`Error testing RPC at ${url}:`, error.message);
return null;
}
}
async function main() {
const rpcEndpoints = [
{
name: 'Ankr',
url: `https://rpc.ankr.com/dogechain`,
},
{
name: 'doge1',
url: `https://rpc-us.dogechain.dog`,
},
{
name: 'doge2',
url: `https://rpc.dogechain.dog `,
},
];
const results = await Promise.all(
rpcEndpoints.map(async (rpc) => {
const latency = await testRPC(rpc.url);
return {
name: rpc.name,
latency: latency !== null ? latency : Infinity,
};
})
);
results.sort((a, b) => a.latency - b.latency);
console.log('Latency results:');
results.forEach((result) => {
console.log(`${result.name}: ${result.latency === Infinity ? 'Failed to test' : result.latency + ' ms'}`);
});
if (results.length >= 2) {
const fastestRPC = results[0].name;
const slowestRPC = results[results.length - 1].name;
console.log(`\nFastest RPC: ${fastestRPC}`);
console.log(`Slowest RPC: ${slowestRPC}`);
}
}
main();