开发者

Why does my timing code always return 0?

开发者 https://www.devze.com 2023-01-15 20:04 出处:网络
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 p

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

精彩评论

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