I am making a rest api call from Android device and was really surprised looking at the difference of speeds when compared to PC.
Below is the image from a rest tool on PC.![enter image description here](https://i.stack.imgur.com/bfQJH.png)
我尝试了一些库,例如 Retrofit、Volley 以及常规异步任务,以从 Android 设备进行相同的休息调用,并注意到以下响应时间。
(Response times with Retrofit library (Time includes converting json data to java objects)).
Test 1: 8372 Ms
Test 2: 7715 Ms
Test 3: 7686 Ms
Test 4: 10128 Ms
Test 5: 7876 Ms
(Response times with Volley. No conversion to Java Objects from Json Data )
Test 1: 6721 MS
Test 2: 6610 MS
Test 3: 6287 MS
Test 4: 6118 MS
Test 5: 6118 MS
I took System.currentTimeMillis()
在拨打电话之前和获得响应之后减去这些值即可得到 Android 程序中的上述响应时间。
如果有人能告诉我如何减少 android 中的响应时间,那将非常有帮助。
仅供参考:我使用 Wifi,并为我的 PC 和 Android 设备使用相同的网络。
这是改造Android代码
RestAdapter adapter = new RestAdapter.Builder()
.setEndpoint(ENDPOINT)
.build();
WeatherApi weatherApi = adapter.create(WeatherApi.class);
startTime = System.currentTimeMillis();
weatherApi.getWeather(location.getLatitude(),location.getLongitude(),new Callback<WeatherInfo>() {
@Override
public void success(WeatherInfo arg0, Response arg1) {
endTime = System.currentTimeMillis();
Log.d("TAG",endTime-startTime + ":Millisecs");
setWeatherInfo(arg0);
if(weatherDialog != null && weatherDialog.isShowing())
weatherDialog.dismiss();
}