[Q] Measure time to access hardware

Search This thread

vaern

New member
May 15, 2014
2
0
Hello!
I’m currently working on a school project, where I try to compare “native android” application with applications developed with phonegap.

Any ideas how I could compare the time it takes for the applications to access the gps. In phonegap I have done the following ( not even sure if is the correct way to do it…):


function getGps(){
var onSuccessr = function (acceleration){
date2 = new Date().getTime();
alert(“time:” (date2 – date1));

}
function onErrorr() {
alert('onError!');

}
date1= new Date().getTime();
navigator.accelerometer.getCurrentAcceleration(onSuccessr, onErrorr);
}

How to do something similar in “native android?
 

SimplicityApks

Senior Member
May 26, 2013
354
344
Aachen
Hello!
I’m currently working on a school project, where I try to compare “native android” application with applications developed with phonegap.

Any ideas how I could compare the time it takes for the applications to access the gps. In phonegap I have done the following ( not even sure if is the correct way to do it…):


function getGps(){
var onSuccessr = function (acceleration){
date2 = new Date().getTime();
alert(“time:” (date2 – date1));

}
function onErrorr() {
alert('onError!');

}
date1= new Date().getTime();
navigator.accelerometer.getCurrentAcceleration(onSuccessr, onErrorr);
}

How to do something similar in “native android?

I don't know what language phonegap is using, but from what I see you access the accelerometer and not the gps...
To measure the time between two events, just save the System.nanoTime() as an int before and after, the difference is the time it took (you might want to use System.currentTimeMillis() instead.

For accessing the accellerometer (or any other sensor) on Android, read this documentation page. Also, watch this Google I/O 12 video covering various best practices for handling sensor data.
 
  • Like
Reactions: vaern

vaern

New member
May 15, 2014
2
0
Thanks for the reply!

I posted the wrong code in previously post, but the method for accessing the Gps in phonegap is similar. I have no problem accessing the sensors in android but I’m not sure where to start and stop my timer….

Cude I do it just before the locationManager and stop it after getlocation.latitude ? or is it some strange asynchrony method?

public void gps(){
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
out.setText("lat" + latitude);


//
}
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    Hello!
    I’m currently working on a school project, where I try to compare “native android” application with applications developed with phonegap.

    Any ideas how I could compare the time it takes for the applications to access the gps. In phonegap I have done the following ( not even sure if is the correct way to do it…):


    function getGps(){
    var onSuccessr = function (acceleration){
    date2 = new Date().getTime();
    alert(“time:” (date2 – date1));

    }
    function onErrorr() {
    alert('onError!');

    }
    date1= new Date().getTime();
    navigator.accelerometer.getCurrentAcceleration(onSuccessr, onErrorr);
    }

    How to do something similar in “native android?

    I don't know what language phonegap is using, but from what I see you access the accelerometer and not the gps...
    To measure the time between two events, just save the System.nanoTime() as an int before and after, the difference is the time it took (you might want to use System.currentTimeMillis() instead.

    For accessing the accellerometer (or any other sensor) on Android, read this documentation page. Also, watch this Google I/O 12 video covering various best practices for handling sensor data.