Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,742,869 Members 39,382 Now Online
XDA Developers Android and Mobile Development Forum

[Q] Measure time to access hardware

Tip us?
 
vaern
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 2
Join Date: May 2014
Default [Q] Measure time to access hardware

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(onS uccessr, onErrorr);
}

How to do something similar in “native android?
 
SimplicityApks
Old
#2  
SimplicityApks's Avatar
Senior Member
Thanks Meter 308
Posts: 287
Join Date: May 2013
Location: Aachen
Quote:
Originally Posted by vaern View Post
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(onS uccessr, 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.
The Following User Says Thank You to SimplicityApks For This Useful Post: [ Click to Expand ]
 
vaern
Old
#3  
Junior Member - OP
Thanks Meter 0
Posts: 2
Join Date: May 2014
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_PROVID ER);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
out.setText("lat" + latitude);


//
}
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes