Tests:
  • Lodash

    AخA
     
    // call once every 1000ms
    var sec = _.throttle(function () {
            console.log('every second');
        }, 1000);
    // call every 100ms
    var hundredMS = _.throttle(function () {
            console.log('every one hundred ms');
        }, 100);
    // a loop for every 33ms
    var loop = function () {
        setTimeout(loop, 33)
        sec();
        hundredMS();
    };
    // start loop
    loop();
  • Native

    x
     
    var throttle = function (func, rate) {
        var lastTime = new Date();
        func = func || function () {};
        rate = rate || 1000;
        // the inner method
        return function () {
            var now = new Date();
            if (now - lastTime >= rate) {
                func();
                lastTime = now;
            }
        };
    };
    var sec = throttle(function () {
            console.log('one sec');
        }, 1000);
    // using it in a loop
    var loop = function () {
        setTimeout(loop, 33);
        sec();
    };
    loop();
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Lodash
    Native

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36
Chrome 97 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
Lodash 26975.3 Ops/sec
Native 270041.2 Ops/sec