jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
let lastInline = 0;
let DELAY = 250;
const work = function() {
}
const throttle = function(delay, callback) {
let last = 0;
const fn = (...args) => {
const now = performance.now();
if (now > last + delay) {
// Invoke the callback now if enough time has passed.
last = now;
callback(...args);
}
};
return fn;
}
const throttleEnsure = function(delay, callback) {
let last = 0;
let handle = undefined;
const fn = (...args) => {
// Cancel any scheduled invocation.
if (handle) {
clearTimeout(handle);
handle = undefined;
}
const now = performance.now();
if (now > last + delay) {
// Invoke the callback now if enough time has passed.
last = now;
callback(...args);
} else {
// Otherwise schedule it to be invoked as soon as possible when the delay expires.
handle = setTimeout(() => fn(...args), delay - (now - last));
}
};
return fn;
}
const throttleWork = throttle(DELAY, () => work());
const throttleEnsureWork = throttleEnsure(DELAY, () => work());
Ready to run.
Test | Ops/sec | |
---|---|---|
Inline Throttle |
| ready |
Wrapped Throttle |
| ready |
Wrapped Throttle with Scheduling |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.