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, schedule) {
let last = 0;
let handle = undefined;
const fn = () => {
// 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();
} else if(schedule) {
// Otherwise schedule it to be invoked as soon as possible when the delay expires.
handle = setTimeout(() => fn(), delay - (now - last));
}
};
return fn;
}
const throttleWork = throttle(DELAY, () => work(), false);
const throttleWorkWithSchedule = throttle(DELAY, () => work(), true);
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.