I'm trying to measure performance improvement of my code when I run my multithreaded android app on a multicore device (like the S3) versus a single core android device. To measure performance, I run the tasks sequentially versus in parallel. I've implemented normal Java threads, which didn't seem to make a difference. I thus tried AsynchTask, but I only got a little bit of performance improvement.
Can you let me know how I can write code that makes sure that each of my tasks / threads are being run on different cores as opposed to a single one? If that is not possible, how can I maximize the use of multiple cores for my app?
Here's the code for the onCreate method of the activity that executes the tasks.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_local_executor);
multiplicationTask t1 = new multiplicationTask();
t1.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
multiplicationTask t2 = new multiplicationTask();
t2.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
multiplicationTask t3 = new multiplicationTask();
t3.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
multiplicationTask t4 = new multiplicationTask();
t4.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Here is the AsynchTask that is run from the onCreate method
class multiplicationTask extends AsyncTask<Integer, Integer, String> {
protected void onPreExecute()
{
Log.v("PrintLN", "Executing Task");
}
@Override
protected String doInBackground(Integer... params) {
//Do lots of floating point operations that are independent of anything whatsoever
}
protected void onPostExecute(String result) {
Log.v("PrintLN", "Done Task: " + resulting_time);
}
}