I am writing real-time debug code in a javascript application. In the update loop I want:
- get current time in milliseconds
- compare last frame time and print frame rate
- set the last frame time to the current time from the variable above
Everything is simple, except that since it is in such a performance-critical piece of code, I try not to call
var d=new Date();
every frame before i call
thisFrameTime = d.getTime();
Is it possible? Is there something like:
d.now
which updates the time in an existing date object?
My thinking is that I want to stay away from memory allocation / gc in debug mode, so this affects the frame rate less - but maybe it's just not how it is done in javascript? (My background is more than C / C ++, so maybe this is the wrong way of thinking for JS?)
I searched google and qaru and can't find an answer that makes me think this is impossible. If this happens, confirmation will be helpful.
To love any thoughts - what is the most effective way to do this?
source share