Android Question B4A - Strange Question (maybe)

AlexOfOz

Active Member
Licensed User
I have created a simple little game for my android phone. It reads through a list of 2000 words on a regular basis.

As I've added more features, I've noticed that it has slowed noticeably and is now taking too long for comfort - 3 or 4 seconds. To track where it was looping or misbehaving, I added a LOG statement at the start of each sub routine.

Here's the strange thing - just by adding those LOG statements, with no other changes, the game is now performing instantly. All time delay has vanished and I'm going to have to add more SLEEP statements to slow it down for usability.

Does anybody know why adding the LOG statements has made the program run vastly faster?

Thanks,
Alex
 

AlexOfOz

Active Member
Licensed User
Both in debug and release mode. The difference with the log statement is magic, so I have left it in and loaded the final release version to my phone.

It's no longer causing any problems, but I was just curious how such a simple thing could fix such a weird thing.
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
It's no longer causing any problems, but I was just curious how such a simple thing could fix such a weird thing.
By adding log() you are actually slowing down the process a bit to display the log-text.

Now may be your code is so written that different events are fired on after another affecting the cpu, or one event is pulling the cpu down (it happens in windows programming too). So the log at that event is giving the cpu time to another event, making the experience faster.
 
Upvote 0

AlexOfOz

Active Member
Licensed User
By adding log() you are actually slowing down the process a bit to display the log-text.

Now may be your code is so written that different events are fired on after another affecting the cpu, or one event is pulling the cpu down (it happens in windows programming too). So the log at that event is giving the cpu time to another event, making the experience faster.
Anand, that sounds like it could be the reason. Yes, I have a lot of looping and ifs going on, so giving the flow a moment to pause at the start makes sense to me now.

Thank-you for your insight and wise words. I appreciate it.

Alex
 
Upvote 0
Top