Editing Loops 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) Added for( .. in ..), set array to random integer values, and set basic operation to adding zero, added some corrections from revison 23, added some tests from other revisions, cleaned up a few things 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) <script> var arr = new Array(800); for (var i = 0; i < arr.length; ++i) arr[i] = (Math.random() * 10001) | 0; </script> 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) 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 i = 0; while (i < arr.length) { arr[i] += 0; i++; }; Test 2 Title Async (check if this is an asynchronous test) Code var i = 0, len = arr.length; while (i < len) { arr[i] += 0; i++; }; Test 3 Title Async (check if this is an asynchronous test) Code var i = arr.length; while (i) { arr[--i] += 0; } Test 4 Title Async (check if this is an asynchronous test) Code var i = arr.length; while (i > 0) { arr[--i] += 0; } Test 5 Title Async (check if this is an asynchronous test) Code var i = arr.length - 1; if (i >= 0) do { arr[i] += 0; } while (i--); Test 6 Title Async (check if this is an asynchronous test) Code for (var i = arr.length; i--;) { arr[i] += 0; }; Test 7 Title Async (check if this is an asynchronous test) Code for (var i = 0; i < arr.length; ++i) { arr[i] += 0; }; Test 8 Title Async (check if this is an asynchronous test) Code for (var i = 0, len = arr.length; i < len; ++i) { arr[i] += 0; }; Test 9 Title Async (check if this is an asynchronous test) Code for (var i = -1; ++i < arr.length;) { arr[i] += 0; }; Test 10 Title Async (check if this is an asynchronous test) Code for (var i = -1, len = arr.length; ++i < len;) { arr[i] += 0; }; Test 11 Title Async (check if this is an asynchronous test) Code arr.forEach(function(x) { x += 0; }); Test 12 Title Async (check if this is an asynchronous test) Code function foo(x) { x += 0; }; arr.forEach(foo); Test 13 Title Async (check if this is an asynchronous test) Code for (var it in arr) { if (arr.hasOwnProperty(it) && isFinite(it)) { arr[it] += 0; } }; Test 14 Title Async (check if this is an asynchronous test) Code var i = 0; for (; arr[i++];) { arr[i] += 0; } Test 15 Title Async (check if this is an asynchronous test) Code var i = arr.length, item; for (; i--; item = arr[i]) { arr[i] += 0; } Test 16 Title Async (check if this is an asynchronous test) Code var l = arr.length for (var i = 0, len = l; i < len; i++) { arr[i] += 0; } Test 17 Title Async (check if this is an asynchronous test) Code for (var i = arr.length; (i -= 8)>0;) { arr[i] += 0; arr[i - 1] += 0; arr[i - 2] += 0; arr[i - 3] += 0; arr[i - 4] += 0; arr[i - 5] += 0; arr[i - 6] += 0; arr[i - 7] += 0; } Test 18 Title Async (check if this is an asynchronous test) Code var i = arr.length - 1; do { arr[i] += 0; } while (i-- > 0);