Hey,

I'm developing a processor-intensive app for Android, which includes nested loops. The development process is still going on, but I'm already trying to find ways to optimize the performance. And I need tips and tricks for it. :)

Mainly I've been changing all the for-loops from (int i = 0; i < x; ++i) format to (Object o : list) format. It has sped the program up a bit, but I still get some spikes when iterating through lists with over 2000 entries, and I use Vector<> as my lists. I've also tried to pull all the needed into local variables, but that's still in progress.

So, if you've got any ideas on how to improve the performance, I would appreciate it a lot. :)

I still get some spikes when iterating through lists with over 2000 entries
>> That will be too much even for desktop, clearly you did not thought your logic throughout. Anyway at the moment I'm reading Android Application Testing Guide. Maybe that can help you in the area of performance

Oops, I made a mistake there, I'm not iterating through those big lists, but I have a loop of max. 30 iterations, which gathers objects and checks them individually if they are found in a list which is over 2000 entries long.

What I've checked so far is that checking if the list contains a single item takes about 0.006 seconds, or 6 ms. Now, if my max. check count is 30, it's about 180ms, which is pretty bad. I also have checked the main loop execution time, which is about 190ms, so I the main delay is coming from the list checks. Is there any way to speed up the list checks? I've thought of dividing the list into smaller lists and categorizing the data in the lists when the program starts, but I'm not sure if that's the smartest or the most efficient way to do so.

It is hard to discuss this sort of thing without prior knowledge of code. Have look on stackoverflow for similar question

Okey, Only thing I changed was to swap the Vector<> to HashSet<>, and the cycle decreased from average of 167ms to mere 18ms. Incredible!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.