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
Test between single instance of request animation frame vs multiple instances of request animation frame
var canvas = document.createElement('canvas'),
ctx = canvas.getContext('2d'),
PI2 = Math.PI * 2,
delayDraw = 250,
time;
function drawLines() {
ctx.beginPath();
ctx.moveTo(10, 10);
ctx.lineTo(50, 50);
ctx.stroke();
ctx.closePath();
}
function drawCircle() {
ctx.beginPath();
ctx.arc(30, 30, 25, 0, PI2, false);
ctx.fillStyle = 'blue';
ctx.fill();
ctx.closePath();
}
function drawRect() {
ctx.fillStyle = 'red';
ctx.fillRect(60, 60, 50, 70);
}
function timeStamp() {
return window.performance && window.performance.now ? window.performance.now() : new Date().getTime();
}
function frame() {
drawCircle();
drawLines();
drawRect();
}
function render() {
if (timeStamp() >= (time || timeStamp())) {
time = timeStamp() + delayDraw;
frame();
}
requestAnimationFrame(render);
}
function render1() {
if (timeStamp() >= (time || timeStamp())) {
time = timeStamp() + delayDraw;
drawCircle();
}
requestAnimationFrame(render1);
}
function render2() {
if (timeStamp() >= (time || timeStamp())) {
time = timeStamp() + delayDraw;
drawRect();
}
requestAnimationFrame(render2);
}
function render3() {
if (timeStamp() >= (time || timeStamp())) {
time = timeStamp() + delayDraw;
drawLines();
}
requestAnimationFrame(render3);
}
if (render) requestAnimationFrame(render, canvas);
if (render1) requestAnimationFrame(render1, canvas);
if (render2) requestAnimationFrame(render2, canvas);
if (render3) requestAnimationFrame(render3, canvas);
Ready to run.
Test | Ops/sec | |
---|---|---|
Single RAF |
| ready |
Multiple RAF |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.