Created
May 4, 2011 09:04
-
-
Save gcoop/954962 to your computer and use it in GitHub Desktop.
Benchmark.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Simple benchmark class in Titanium. | |
* | |
* @usage | |
* Benchmark.start(); | |
* Benchmark.addMarker("Did some cool stuff."); | |
* Benchmark.end(); // Print that shit out. | |
* | |
* @author Gavin Cooper. | |
*/ | |
Benchmark = (function () { | |
var markers = []; | |
return { | |
start: function () { | |
markers = []; | |
markers.push({title: "Start", value: new Date()}); | |
}, | |
addMarker: function (title) { | |
if (markers.length <= 0) { | |
Benchmark.start(); | |
} | |
markers.push({title: title, value: new Date()}); | |
}, | |
end: function () { | |
markers.push({title: "End", value: new Date()}); | |
Ti.API.debug("==== BENCHMARK START ===="); | |
for (var i = 1; i < markers.length; i++) { | |
var duration = markers[i].value.getTime() - markers[i - 1].value.getTime(); | |
Ti.API.debug("==== "+markers[i].title+" - "+duration+" m/s"); | |
if (i == (markers.length - 1)) { | |
Ti.API.debug("==== Total Time: "+(markers[i].value.getTime() - markers[0].value.getTime())+" m/s"); | |
} | |
} | |
Ti.API.debug("==== BENCHMARK END ===="); | |
markers = []; | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment