JSFiddle - React, Tailwind, and code Playground

by mistakster

JavaScript

function test(fn, n, done) {

    var delta = [],
        start = [],
        i, j;

    for (i = 0, j = 0; i < n; i++) {
        (function (i) {
            start[i] = window.performance.now();
            fn(function () {
                delta[i] = performance.now() - start[i];
                j++;
                if (j >= n) {
                    done(Math.min.apply(null, delta), Math.max.apply(null, delta));
                }
            });
        }(i));
    }

}


function results(title, min, max) {
    console.log(title);
    console.log("min: ", min);
    console.log("max: ", max);
    console.log("=====");

}

test(setTimeout, 10, function (min, max) {
    results("setTimeout 10:", min, max);

    test(requestAnimationFrame, 10, function (min, max) {
        results("requestAnimationFrame 10:", min, max);

        test(setTimeout, 1e5, function (min, max) {
            results("setTimeout 1e5:", min, max);

            test(requestAnimationFrame, 1e5, function (min, max) {
                results("requestAnimationFrame 1e5:", min, max);
            });
        });

    });
});