Javascript FPS calculation less than 1 millisecond

Is it possible to measure time intervals of less than 1 millisecond, which are supported in all browsers, which I know in only one way, which is in Chrome.

Chrome Method: window.performance.now()

I am currently doing FPS measurements in milliseconds of a time interval, but if less than 1 ms has passed, I get infinity because the two numbers are rounded to the nearest millisecond, so they have the same value.

Does anyone know that cross browser function calculates less than 1 millisecond time span in javascript?

+5
source share
3 answers

Here, how you get accurate measurements without an accurate timer, while what you do often happens, and I hope they do it in your case.

/ . :

        var start = Date.now();
        ... (stuff to be timed)
        var now = Date.now();

        if (DEBUG.enabled) {
            var profile_this_iter = now - start;
            profile += (profile_this_iter - profile) * 0.02;
        }

0,02 . , . , 0,5 , 1 0 ( 1 ).

, , . , javascript FPS. , , . , , - . ( 0,02) ( ), , , ,

+3

fps, . , , .

var fpsStart = new Date().getTime();
var fpsCounting = 0;
var fps = 0;
start_the_first_frame();

// Loop
function update(){
    do_time_consuming_stuff();
    fpsCounting++;
    var thisFrame = new Date().getTime();
    if(thisFrame - fpsStart >= 1000){
        fpsStart += 1000;
        fps = fpsCounting;
        fpsCounting = 0;
    }
    request_next_animation_frame();
}

P.S. , , .

, lwjgl ...

, @StevenLu, , 0,5 "fps" (, 0,25 ), fps .

+1

Chrome 20, , JS , . 4 1000

0

All Articles