基于javascript的钛合金时间测量
我已经用钛合金创建了一个应用程序,它可以创建10000个按钮并将它们添加到一个窗口中。我的目标是测量整个创建过程的时间,以便将其与其他跨平台解决方案进行比较 现在我的问题是:所有的按钮都画得很完美,但正如标题所说,时间测量值太差了,用真正的秒表计时大约需要一分钟,但使用.getTime比较时,它给了我0.02分钟基于javascript的钛合金时间测量,javascript,titanium,Javascript,Titanium,我已经用钛合金创建了一个应用程序,它可以创建10000个按钮并将它们添加到一个窗口中。我的目标是测量整个创建过程的时间,以便将其与其他跨平台解决方案进行比较 现在我的问题是:所有的按钮都画得很完美,但正如标题所说,时间测量值太差了,用真正的秒表计时大约需要一分钟,但使用.getTime比较时,它给了我0.02分钟 function renderButtons() { var win = Ti.UI.createWindow({ backgroundColor: 'B8B8
function renderButtons() {
var win = Ti.UI.createWindow({
backgroundColor: 'B8B8B8',
exitOnClose: true,
fullscreen: 'false',
title: 'Label Demo'
});
win.open();
var count = 0;
var Pwidth = Ti.Platform.displayCaps.platformWidth;
var Pheight = Ti.Platform.displayCaps.platformHeight;
var widthRan = 0;
var heightRan = 0;
var left;
var top;
var color;
var time = '0.0';
var elapsed = '0.0';
var start = '0.0';
start = new Date().getTime();
for (count = 0; count < 10000; count++) {
left = Math.floor((Math.random()*Pwidth));
top = Math.floor((Math.random()*Pheight));
widthRan = Math.floor((Math.random()*100));
heightRan = Math.floor((Math.random()*100));
color = getRandomColor();
var pixel = Ti.UI.createButton({
center: { x:left, y:top },
width: widthRan,
height: heightRan,
textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
text: 'Back',
color: 'white',
backgroundColor: color
});
win.add(pixel);
}
elapsed = new Date().getTime();
time = elapsed - start;
var seconds = time/1000;
var mins = seconds/60;
win.close();
alert(mins.toString());
}
我的时间测量方法有问题吗,或者这可能是钛的问题?这很奇怪,因为它对我的矩阵乘法非常有效。您在alert alerttime.toString中显示时间;它不会给你以秒或分为单位的时间差。警报秒;将以秒和分钟为单位显示差异;将以分钟为单位显示差异。您正在测量初始化10000个按钮对象所需的时间,而无需在屏幕上绘制它们。要计算从启动应用程序到用户看到屏幕上所有按钮的确切时间,需要使用连接到窗口对象的事件侦听器 请尝试以下方法:
function renderButtons() {
var win = Ti.UI.createWindow({
backgroundColor: 'B8B8B8',
exitOnClose: true,
fullscreen: 'false',
title: 'Label Demo'
});
var start = new Date().getTime();
for (var count = 0; count < 1000; count++) {
win.add( createRandomButton() );
}
alert('init: ' + (new Date().getTime() - start));
win.addEventListener('postlayout', function(){
alert('postlayout: ' + (new Date().getTime() - start));
});
win.open();
}
对不起,我的坏-提供了旧代码。现在代码与应用程序中的代码相同。时间变量给了我以毫秒为单位的差值,这给了我1503,这是远远不够的。
win.addEventListener('postlayout', function(){
alert('postlayout: ' + (new Date().getTime() - start));
win.close();
});