Editing closure vs compund 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) 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) var Edge = function() { this.a = 0; this.nextEdge = null; // +20 other members } function ProcessEdge(e) { // some processing and then e.Value = e.Value.nextEdge; // instead of e = e.nextEdge; return e.Value.a-10; } function ProcessEdge2(e) { // some processing and then e = e.nextEdge; // instead of e = e.nextEdge; return {Value: e, Res: e.a-10}; } var global_ret = 0; function ProcessEdge3(e) { // some processing and then e = e.nextEdge; // instead of e = e.nextEdge; global_ret = e.a-10; return e; } var global_val = {}; function ProcessEdge4(e) { // some processing and then e = e.nextEdge; // instead of e = e.nextEdge; global_ret = e.a-10; global_val = e; } var global_val6 = function(){this.Value=new Edge();}; function ProcessEdge6(e) { // some processing and then e = e.nextEdge; // instead of e = e.nextEdge; global_ret = e.a-10; global_val6.Value = e; } function main(a) { // And the calling part: var res=0, res2, e, b; for (var i=0;i<10000;i++) { e = new Edge(); b = new Edge(); b.a = i*a; e.nextEdge = b; // some processing and then res += (function () { e = { Value: e }; res2 = ProcessEdge(e); e = e.Value; return res2; }) .call(this); if (e!=b) res+=1000; } return res; } function main2(a) { var res=0, res2, e, b; for (var i=0;i<10000;i++) { // And the calling part: e = new Edge(); b = new Edge(); b.a = i*a; e.nextEdge = b; // some processing and then res2 = ProcessEdge2(e); e = res2.Value; res += res2.Res; if (e!=b) res+=1000; } return res; } function main3(a) { var res=0, res2, e, b; for (var i=0;i<10000;i++) { // And the calling part: e = new Edge(); b = new Edge(); b.a = i*a; e.nextEdge = b; // some processing and then e = ProcessEdge3(e); res += global_ret; if (e!=b) res+=1000; } return res; } function main4(a) { var res=0, res2, e, b; for (var i=0;i<10000;i++) { // And the calling part: e = new Edge(); b = new Edge(); b.a = i*a; e.nextEdge = b; // some processing and then ProcessEdge4(e); e = global_val; res += global_ret; if (e!=b) res+=1000; } return res; } function main5(a) { // And the calling part: var res=0, res2, e, b, d={}; for (var i=0;i<10000;i++) { e = new Edge(); b = new Edge(); b.a = i*a; e.nextEdge = b; // some processing and then res += (function () { d.Value = e; res2 = ProcessEdge(d); e = d.Value; return res2; })(); if (e!=b) res+=1000; } return res; } function main6(a) { var res=0, res2, e, b; for (var i=0;i<10000;i++) { // And the calling part: e = new Edge(); b = new Edge(); b.a = i*a; e.nextEdge = b; // some processing and then ProcessEdge6(e); e = global_val6.Value; res += global_ret; if (e!=b) res+=1000; } return res; } function main7(a) { // And the calling part: var res=0, res2, e, b; for (var i=0;i<10000;i++) { e = new Edge(); b = new Edge(); b.a = i*a; e.nextEdge = b; // some processing and then res += _ProcessEdge(); if (e!=b) res+=1000; } return res; function _ProcessEdge() { // some processing and then e = e.nextEdge; return e.a-10; } } function main8(a) { var pseudo_global_ret = 0; var res=0, res2, e, b; for (var i=0;i<10000;i++) { e = new Edge(); b = new Edge(); b.a = i*a; e.nextEdge = b; // some processing and then _ProcessEdge(); res += pseudo_global_ret; if (e!=b) res+=1000; } return res; function _ProcessEdge() { // some processing and then e = e.nextEdge; pseudo_global_ret = e.a-10; // instead of return e.a-10 } } function main9(a) { var res=0, res2, e, b; for (var i=0;i<10000;i++) { e = new Edge(); b = new Edge(); b.a = i*a; e.nextEdge = b; // some processing and then _ProcessEdge(); res += global_ret; if (e!=b) res+=1000; } return res; function _ProcessEdge() { // some processing and then e = e.nextEdge; global_ret = e.a-10; // instead of return e.a-10 } } function main10(a) { var res=0, res2, e, b; for (var i=0;i<10000;i++) { e = new Edge(); b = new Edge(); b.a = i*a; e.nextEdge = b; // now the same without any functions e = e.nextEdge; res += e.a-10; if (e!=b) res+=1000; } return res; } var a,b,c; 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 a = main(10); b = main(20); c = main(30); Test 2 Title Async (check if this is an asynchronous test) Code a = main2(10); b = main2(20); c = main2(30); Test 3 Title Async (check if this is an asynchronous test) Code a = main3(10); b = main3(20); c = main3(30); Test 4 Title Async (check if this is an asynchronous test) Code a = main4(10); b = main4(20); c = main4(30); Test 5 Title Async (check if this is an asynchronous test) Code a = main5(10); b = main5(20); c = main5(30); Test 6 Title Async (check if this is an asynchronous test) Code a = main6(10); b = main6(20); c = main6(30); Test 7 Title Async (check if this is an asynchronous test) Code a = main7(10); b = main7(20); c = main7(30); Test 8 Title Async (check if this is an asynchronous test) Code a = main8(10); b = main8(20); c = main8(30); Test 9 Title Async (check if this is an asynchronous test) Code a = main9(10); b = main9(20); c = main9(30); Test 10 Title Async (check if this is an asynchronous test) Code a = main10(10); b = main10(20); c = main10(30);