Execution time of the program written using Android SDK

  • Thread starter Thread starter AC Question
  • Start date Start date
A

AC Question

I need to calculate the time taken to execute the sorting program given
below. I am new to android programming and I just found an article to
use TimingLogger but in the prompt when I type

adb logcat -v time SortTag:V *:E
to know the time of execution it gives me the following error.

Errors displayed

C:\Users\Dell\AndroidStudioProjects\Sort>adb shell setprop log.tag.SortTag
VERBOSE

C:\Users\Dell\AndroidStudioProjects\Sort>adb logcat -v time SortTag:V *:E

--------- beginning of main
--------- beginning of system
06-09 12:51:55.725 E/memtrack(11184): Couldn't load memtrack module
(No such file or directory)
06-09 12:51:55.725 E/android.os.Debug(11184): failed to load memtrack
module: -2
06-09 12:51:56.160 E/JavaBinder( 1232): !!! FAILED BINDER TRANSACTION !!!
06-09 12:51:56.183 E/InputDispatcher( 1232): channel '3bf07b77
com.example.android.sort/com.example.android.
sort.MainActivity (server)' ~ Channel is unrecoverably broken and will be
disposed!
06-09 12:52:05.459 E/memtrack(11290): Couldn't load memtrack module
(No such file or directory)
06-09 12:52:05.459 E/android.os.Debug(11290): failed to load
memtrack module: -2
06-09 12:52:05.527 E/art (11290): Thread attaching while runtime
is shutting down: Binder_1

Can anyone help me with this or let me know if any other method
can be used. I had used emulator for execution of the program

Program

MainActivity.java

package com.example.android.sort;

public class MainActivity extends ActionBarActivity {

TextView txtResult;
Button BRand;
EditText editTextName;

public double n;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextName = (EditText) findViewById(R.id.editTextName);

txtResult = (TextView) findViewById(R.id.txtResult);
BRand = (Button) findViewById(R.id.BRand);

BRand.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
String res="";
int n=0;

TimingLogger timings = new TimingLogger("SortTag","Sort");

n=Integer.parseInt(editTextName.getText().toString());
Random rand = new Random();
int[] array = new int[n];
for (int i = 0; i < n; i++){
array=i;
}

Collections.shuffle(Arrays.asList(array));

for (int i = 0; i < ( n - 1 ); i++)
{
for (int j = 0; j < n - i - 1; j++) {
if (array[j] < array[j+1]) {
int temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}

for(int i=0;i<n;i++)
{
res+=String.valueOf(array)+"\n";
}
txtResult.setMovementMethod(new ScrollingMovementMethod());
txtResult.setText(res);
timings.dumpToLog();
};
});

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}
 
Just have your program log the exact time at the start of the sort and at the end of the sort. Make the calls as single-line as you can, so you can comment them out once you've gotten the sort as short as possible.
 

Members online

Forum statistics

Threads
956,225
Messages
6,966,996
Members
3,163,486
Latest member
wardsworthda69