Skip to content

Instantly share code, notes, and snippets.

@tonylukasavage
Last active August 29, 2015 14:01
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 tonylukasavage/95349e21d2b2f4d6b6d3 to your computer and use it in GitHub Desktop.
Save tonylukasavage/95349e21d2b2f4d6b6d3 to your computer and use it in GitHub Desktop.
perf test
var win = Ti.UI.createWindow();
var key = '#foo';
var start = new Date().getTime();
for (var i = 0; i < 10000; i++) {
if (key.indexOf('#') === 0 && key !== '#' && !win.__iamalloy) {
var bar = 1;
}
}
console.log('time (__iamalloy): ' + ((new Date().getTime()) - start) + 'ms');
start = new Date().getTime();
for (var i = 0; i < 10000; i++) {
if (key.indexOf('#') === 0 && key !== '#' && typeof win.getApiName === 'function') {
var bar = 1;
}
}
console.log('time (getApiName): ' + ((new Date().getTime()) - start) + 'ms');
start = new Date().getTime();
try {
for (var i = 0; i < 10000; i++) {
if (key.indexOf('#') === 0 && key !== '#') {
var bar = 1;
}
}
} catch (e) {
throw new Error('WTF');
}
console.log('time (exception): ' + ((new Date().getTime()) - start) + 'ms');
start = new Date().getTime();
for (var i = 0; i < 10000; i++) {
if (key.indexOf('#') === 0 && key !== '#') {
var bar = 1;
}
}
console.log('time: ' + ((new Date().getTime()) - start) + 'ms');
[INFO] time (__iamalloy): 144ms
[INFO] time (getApiName): 58ms
[INFO] time (exception): 1ms
[INFO] time: 1ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment