1
我使用以下函數來更新並調用構建動畫條形圖的drawAccel();
函數。使用循環牆壁時間優化功能性能
function messagecb(header, message) {
if(header.type == 6) {
// processEchoReply(message);
} else if(header.type == 4) {
// accel
var accels = message.b64UnpackAccelMsg();
for(var index = 0; index < accels.length; ++index) {
var accel = accels[index];
var totalClock = accelEpochAdjust(accel.clock);
addAccelDatum(totalClock, accel.x, accel.y, accel.z);
}
if (typeof messagecb.counter == 'undefined') {
messagecb.counter = 0;
}
++messagecb.counter;
if (messagecb.counter % 10 === 0) {
drawAccel();
}
} else if(header.type == 3) {
// info
var info2 = message.b64UnpackInfo2Msg();
displayCurrentPosition(info2.fixtime, info2.lat, info2.lon, info2.alt);
displayMobileStatus(info2.rssi, info2.bandClass, info2.batt);
} else if(header.type == 11) {
btReceive(header, message);
}
}
我在IE8中遇到一些間歇性的性能問題,但。所以我想 收集更新for循環內運行的延遲掛牆時間,並且不要調用drawAccel()
渲染器,除非我使用的牆壁時間少於50%。
僞代碼示例:
if ((lastEnteredTime - lastExitedTime)/(currentTime - lastEnteredTime) < .5){
drawAccel();
} else {
//do nothing
}
我的問題是我不知道我該怎麼去獲得最後輸入的時間和循環的最後一次EXITED這樣我就可以運行這個條件。有任何想法嗎?謝謝!
它看起來像是越來越近,因爲它提供了當前時間和開始時間。 'var timeElapsedInMs'對我來說似乎是我的情況中的'lastExitedTime',並且當前顯然是當前時間,所以現在我只需要知道如何獲取循環的最後輸入時間。 –
@Stavros_S - 確實接近 - 我最後的編輯應該讓你更接近一點。 –
謝謝!今晚會攻擊它,並讓你知道它是如何工作的。 –