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
Is requestAnimationFrame faster than setInterval?
<script>
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback ){
window.setTimeout(callback, 1000 / 60);
};
})();
var canvas, context;
function init() {
canvas = document.createElement('canvas');
canvas.width = 256;
canvas.height = 256;
context = canvas.getContext('2d');
document.body.appendChild(canvas);
}
function draw() {
var time = new Date().getTime() * 0.002;
var x = Math.sin(time) * 96 + 128;
var y = Math.cos(time * 0.9) * 96 + 128;
context.fillStyle = 'rgb(245,245,245)';
context.fillRect(0, 0, 255, 255);
context.fillStyle = 'rgb(255,0,0)';
context.beginPath();
context.arc(x, y, 10, 0, Math.PI * 2, true);
context.closePath();
context.fill();
}
function animate1() {
requestAnimFrame(animate1);
draw();
}
function animate2() {
window.setTimeout(animate2, 1000 / 60);
draw();
}
init();
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
requestAnimationFrame |
| ready |
setInterval |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.