Skip to content

Instantly share code, notes, and snippets.

@meeech
Created April 17, 2013 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meeech/5407137 to your computer and use it in GitHub Desktop.
Save meeech/5407137 to your computer and use it in GitHub Desktop.
Test using Ti.App events vs using JS only event system.
var win = Ti.UI.createWindow({backgroundColor: '#fff'})
, Emitter = require('emitter') //https://github.com/component/emitter
, event = new Emitter()
, limit = 10000
, i = 0
, startTime
;
var buttonTi = Ti.UI.createButton({title: 'start-Ti', left: 10});
var buttonJs = Ti.UI.createButton({title: 'start-js', right: 10});
win.add(buttonTi);
win.add(buttonJs);
win.open();
var start = function(){
console.log('->Starting');
i = 0;
startTime = new Date();
};
var stop = function() {
var now = new Date();
console.log(now - startTime, 'ms');
};
var eventData = {data: "to pass", to: "listener" };
buttonTi.addEventListener('click', function() {
start();
Ti.App.fireEvent('app:custom', eventData);
});
buttonJs.addEventListener('click', function() {
start();
event.emit('app:custom', eventData );
});
Ti.App.addEventListener('app:custom', function(e) {
i++;
if(i < limit) {
Ti.App.fireEvent('app:custom', eventData);
}
else {
console.log('->Stopping Ti');
stop();
}
});
event.on('app:custom', function(e) {
i++;
if(i < limit) {
event.emit('app:custom', eventData);
}
else {
console.log('->Stopping Js');
stop();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment