网速检测

This commit is contained in:
sjm 2023-12-24 14:40:42 +08:00
parent 85fdf7dbcb
commit dcfeeecea2

View File

@ -1,5 +1,7 @@
package com.lovenav.utils; package com.lovenav.utils;
import java.io.BufferedReader; import java.io.BufferedReader;
import com.alibaba.fastjson2.JSON;
import org.apache.http.client.config.RequestConfig; import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
@ -102,7 +104,7 @@ public class UrlCheckUtil {
} }
} }
public static void url_speed(String url) { public static String url_speed(String url) {
String url_check = url; String url_check = url;
int numRequests = 10; int numRequests = 10;
long totalResponseTime = 0; long totalResponseTime = 0;
@ -119,6 +121,6 @@ public class UrlCheckUtil {
} }
} }
double averageResponseTime = (double) totalResponseTime / (1 * numRequests); double averageResponseTime = (double) totalResponseTime / (1 * numRequests);
System.out.println("Average response time: " + averageResponseTime + " ms"); return JSON.toJSONString(averageResponseTime + " ms");
} }
} }