async function testDownloadSpeed() { const downloadUrl = '/testfile.bin'; // 必须是 ≥5MB 的文件 const startTime = performance.now(); try { const response = await fetch(`${downloadUrl}?cache=${Math.random()}`, { cache: 'no-store' }); const blob = await response.blob(); // 确保完全读取数据 const endTime = performance.now(); const fileSizeMB = blob.size / (1024 * 1024); const duration = (endTime - startTime) / 1000; const speedMbps = ((fileSizeMB * 8) / duration).toFixed(2); console.log(`📥 下载速度:${speedMbps} Mbps`); return { speed: speedMbps, fileSizeMB: fileSizeMB.toFixed(2), duration: duration.toFixed(2) }; } catch (e) { console.error('下载测速失败:', e); } }