A quick vibe-coded site to test response times of PLC.directory mirrors (over 3 attempts)
1import { Mirror } from "@/config/mirrors"; 2import { BenchmarkResult } from "@/types/benchmark"; 3 4export const benchmarkMirror = async ( 5 mirror: Mirror, 6 did: string 7): Promise<BenchmarkResult> => { 8 const url = `${mirror.url}/${did}`; 9 const startTime = performance.now(); 10 11 try { 12 const response = await fetch(url); 13 const endTime = performance.now(); 14 const responseTime = endTime - startTime; 15 16 if (!response.ok) { 17 return { 18 mirrorName: mirror.name, 19 mirrorUrl: mirror.url, 20 responseTime, 21 status: "error", 22 statusCode: response.status, 23 error: `HTTP ${response.status}`, 24 }; 25 } 26 27 const data = await response.json(); 28 29 return { 30 mirrorName: mirror.name, 31 mirrorUrl: mirror.url, 32 responseTime, 33 status: "success", 34 statusCode: response.status, 35 data, 36 }; 37 } catch (error) { 38 const endTime = performance.now(); 39 return { 40 mirrorName: mirror.name, 41 mirrorUrl: mirror.url, 42 responseTime: endTime - startTime, 43 status: "error", 44 error: error instanceof Error ? error.message : "Unknown error", 45 }; 46 } 47}; 48 49export const benchmarkAllMirrors = async ( 50 mirrors: Mirror[], 51 did: string 52): Promise<BenchmarkResult[]> => { 53 const promises = mirrors.map((mirror) => benchmarkMirror(mirror, did)); 54 return Promise.all(promises); 55};