开发者

Why does my timing code always return 0?

i was optimizing my html5 game engine for performance issues and i want to know how much time a render process needs.So i got a bunch of render function开发者_开发问答s.Each of them render seperated parts of the game.. such as blocks , players etc.

function gameRender() {
    var d1 = new Date();
    var firstTime = d1.getTime();

    // render stuff

    var second = d1.getTime();
    console.log("Renders took " + (second-firstTime));
}


Hmm I got the problem: after a little search on Google , I realized that I must use a second date object for the second variable, so here is a fixed version:

function gameRender() {
    var d1 = new Date();
    var firstTime = d1.getTime();

    // render stuff

    var d2 = new Date();
    var second = d2.getTime();
    console.log("Renders took " + (second-firstTime));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜