A few weeks ago, I’ve been playing with some app that was running a slow; however, it was not so easy to understand which part of the code exactly was causing the problem. I decided to print out debug messages, one every few blocks of code, calculating how much time each of those blocks was taking. The first code I uses looked like this:
|
1 2 3 4 5 6 7 8 9 |
var start = (new Date()).getTime(); var now = start; Ti.API.info("Time passed: " + (now-start) + "ms"); // some code here now = (new Date()).getTime(); Ti.API.info("Time passed: " + (now-start) + "ms"); start = now; |
This code works fine if you print out just a few messages, and if you find the core of the problem within 10 minutes; afterwards, you will get mad understanding what’s going on. I know, you can just print out different messages, instead of the time only, but that means to copy, paste, change, search etc. To avoid all that, I decided to implement a module, called TiTimeLogger. This module would apply the above idea, adding some additional feature such as the line number. Continue reading
