From abb2a568bbf35f4e616610719eb49d3c4f748f3f Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 23 Oct 2020 10:35:29 +0530 Subject: [PATCH] fix an incorrect reference and add a small script to help profile timer accuracy --- scripts/tests/throttle-test.js | 34 ++++++++++++++++++++++++++++++++++ www/common/common-util.js | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 scripts/tests/throttle-test.js diff --git a/scripts/tests/throttle-test.js b/scripts/tests/throttle-test.js new file mode 100644 index 000000000..e84fc4a8a --- /dev/null +++ b/scripts/tests/throttle-test.js @@ -0,0 +1,34 @@ +var Util = require("../../lib/common-util"); + +(function (throttle) { + var last = 0; + var last_call = 0; + var f = Util.throttle(function (boop) { + var now = +new Date(); + if (last) { + console.log("last execution was %sms ago", now - last); + } else { + console.log("this is the first execution"); + } + last = now; + + //console.log('time of execution:', now); + console.log(boop); + }, 1000); + + [150, 250, 580, 850, 1500, 2200, 3990, 5000].forEach(function (delay) { + setTimeout(function () { + var now = +new Date(); + + if (last_call) { + console.log("last call was %sms ago", now - last_call); + } + + last_call = now; + //console.log("time of call for delay(%s):", delay, now); + f(delay); + }, delay); + }); +}(Util.throttle2)); + + diff --git a/www/common/common-util.js b/www/common/common-util.js index e781bc2eb..41797e7c8 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -330,7 +330,7 @@ // else run `f` with the most recently supplied arguments f.apply(null, args); - }, ms); + }, delay); }; var g = function () {