Skip to content

Instantly share code, notes, and snippets.

@dezinezync
Forked from pec1985/test1.js
Created August 11, 2012 19:23
Show Gist options
  • Save dezinezync/3326522 to your computer and use it in GitHub Desktop.
Save dezinezync/3326522 to your computer and use it in GitHub Desktop.
Optimizing Appcelerator's Titanium
/**
* Test #1
* Adding 10,000 Ti.UI.TableViewRows to a Ti.UI.TableView
* The rows have the Ti.UI.iPhone.TableViewCellSelectionStyle.BLUE constant in them
*
* Total time in my Mac: 1228ms
*/
var win = Ti.UI.createWindow({
backgroundColor: '#ccc'
});
win.open();
var table = Ti.UI.createTableView();
win.add(table);
// Start the timer
var time = new Date().getTime();
// ==========================================
var data = [];
for(var i = 0; i < 10000; i++){
data.push(
Ti.UI.createTableViewRow({
title:'Row #'+i,
selectionStyle: Ti.UI.iPhone.TableViewCellSelectionStyle.BLUE
})
);
}
table.setData(data);
// ==========================================
// End the timer
var end = new Date().getTime();
Ti.API.info('It took ' + (end - time)+'ms');
// 1228ms
/**
* Test #2
* Adding 10,000 Ti.UI.TableViewRows to a Ti.UI.TableView
* A JavaScript variable holds the Ti.UI.iPhone.TableViewCellSelectionStyle.BLUE constant
* That variable is then passed to the rows, this way we don't call Ti every time
*
* Total time in my Mac: 826ms
*/
var win = Ti.UI.createWindow({
backgroundColor: '#ccc'
});
win.open();
var table = Ti.UI.createTableView();
win.add(table);
var SELECTION_STYLE_BLUE = Ti.UI.iPhone.TableViewCellSelectionStyle.BLUE;
// Start the timer
var time = new Date().getTime();
// ==========================================
var data = [];
for(var i = 0; i < 10000; i++){
data.push(
Ti.UI.createTableViewRow({
title:'Row #'+i,
selectionStyle: SELECTION_STYLE_BLUE
})
);
}
table.setData(data);
// ==========================================
// End the timer
var end = new Date().getTime();
Ti.API.info('It took ' + (end - time)+'ms');
// 826ms
/**
* Test #3
* Adding 10,000 JavaScript Objects to a TableView
* A JavaScript variable holds the Ti.UI.iPhone.TableViewCellSelectionStyle.BLUE constant
* That variable is then passed to the Object, this way we don't call Ti every time
* In this test, I have an object instead of a Ti.UI.TableViewRow
*
* Total time in my Mac: 460ms
*/
var win = Ti.UI.createWindow({
backgroundColor: '#ccc'
});
win.open();
var table = Ti.UI.createTableView();
win.add(table);
var SELECTION_STYLE_BLUE = Ti.UI.iPhone.TableViewCellSelectionStyle.BLUE;
// Start the timer
var time = new Date().getTime();
// ==========================================
var data = [];
for(var i = 0; i < 10000; i++){
data.push({
title:'Row #'+i,
selectionStyle: SELECTION_STYLE_BLUE
});
}
table.setData(data);
// ==========================================
// End the timer
var end = new Date().getTime();
Ti.API.info('It took ' + (end - time)+'ms');
// 460
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment