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.
I tried few libraries like Retrofit, Volley and also regular Async task to make the same rest call from android device and noticed following response times.
(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()
before making a call and after getting the response and subtracted those values to get above response time in Android program.
It would be really helpful if some one can show me how to reduce the response time in android.
FYI: I am on Wifi and using same network both for my PC and Android device.
Here is the Retrofit Android code
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();
}
WeatherInfo
object. The times you have given will contain that additional conversion time. How large is the body you get back and can you post the WeatherInfo POJO class you are using? – Zsazsa