다음 코드를 사용하여 http 서버에서 일부 텍스트를 검색합니다. 크기는 1kB 미만이고 0.002 밀리 초 단위로 생성됩니다.Android url.openStream slow?
그러나 데이터를 가져 오는 데는 600 밀리 초가 걸리지 만 대개는 2000 밀리 초와 5000 밀리 초 사이가 걸릴 수 있습니다.
다음과 같은 코드가 사용된다 :
long starttime = System.currentTimeMillis();
StringBuffer SB = new StringBuffer();
Common.toLog("101 took "+ (System.currentTimeMillis() - starttime) + " ms");
try {
URL url = new URL(Common.server+request);
Common.toLog("102 took "+ (System.currentTimeMillis() - starttime) + " ms");
InputStreamReader ISR = new InputStreamReader(url.openStream());
Common.toLog("102a took "+ (System.currentTimeMillis() - starttime) + " ms");
BufferedReader in = new BufferedReader(ISR);
Common.toLog("103 took "+ (System.currentTimeMillis() - starttime) + " ms");
String inputLine;
while ((inputLine = in.readLine()) != null) {
SB.append(inputLine);
}
in.close();
Common.toLog("105 took "+ (System.currentTimeMillis() - starttime) + " ms");
} catch (IOException e)
{
Common.toLog("Could not make connection 1");
showMSG(R.string.ERROR_NO_INTERNET, true);
}
가장 시간이 많이 걸리는 방법은 로그 - 포인트 (102)과 점 (102A) 사이에있다. 크롬을 사용하면 the page을 300-350ms 내에로드 할 수 있습니다. 이 데이터를보다 효율적으로 검색 할 수있는 방법이 있는지 알고 싶습니다.
그것은 다음과 같은 스크립트를 사용하여 이전보다 더 예를 들어, 당신은 HttpGet 요청을 시도 할 수 있습니다. html 그러나 : 첫 번째 요청에 대한 응답 시간은 다음 요청에 대해 +/- 700 초에 비해 1600ms가 걸립니다. –