Editing Dynamic vs Static rAF frameTime This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <canvas id="gameCanvas" width="300" height="500"> Canvas element not supported </canvas> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) // http://paulirish.com/2011/requestanimationframe-for-smart-animating/ // http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating // requestAnimationFrame polyfill by Erik Möller // fixes from Paul Irish and Tino Zijdel (function() { var lastTime = 0; var vendors = ['ms', 'moz', 'webkit', 'o']; for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']; window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame']; } if (!window.requestAnimationFrame) window.requestAnimationFrame = function(callback, element) { var currTime = new Date().getTime(); var timeToCall = Math.max(0, 16 - (currTime - lastTime)); var id = window.setTimeout(function() { callback(currTime + timeToCall); }, timeToCall); lastTime = currTime + timeToCall; return id; }; if (!window.cancelAnimationFrame) window.cancelAnimationFrame = function(id) { clearTimeout(id); }; }()); ourCanvas = document.getElementById("gameCanvas"); context = ourCanvas.getContext('2d'); var img = new Image() img.src = 'https://www.google.com/intl/ar_ALL/images/logos/images_logo_lg.gif'; Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code var filterStrength = 50; var frameTime = 30, lastLoop = new Date, thisLoop; function gameLoop() { var thisFrameTime = (thisLoop = new Date) - lastLoop; frameTime += (thisFrameTime - frameTime) / filterStrength; lastLoop = thisLoop; setTimeout(function() { //code for any thing context.drawImage(img, 0, 0, 100, 100); requestAnimationFrame(gameLoop); }, 1000 / frameTime); } Test 2 Title Async (check if this is an asynchronous test) Code var frameTime = 30; function gameLoop() { setTimeout(function() { //code for any thing context.drawImage(img, 0, 0, 100, 100); requestAnimationFrame(gameLoop); }, 1000 / frameTime); }