Editing perf impact of passing references 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) This test is attempting to show the performance impact of passing references compared to normal scope chain lookups. Check out [Compact.js](https://github.com/DominikGuzei/Compact.js), that's based on [Require.js](http://http://requirejs.org/) Dominik Guzei [Wizzart](http://wizzart.at) by the way -> I'm searching for a JavaScript internship :) ## Modified By [@jdalton](http://twitter.com/jdalton) 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> ui.benchmarks[0].setup = function() { var Library = { 'util': { 'add': function(a, b) { return a + b; } }, 'cool': { 'Class': function(startValue) { this.value = startValue; } } }; Library.cool.Class.prototype = { 'addToValue': function(value) { this.value = Library.util.add(this.value, value); } }; }; ui.benchmarks[1].setup = function() { var cache = {}; function define(namespace, includes, callback) { var i = -1; if (arguments.length < 3) { callback = includes; includes = []; } // convert string namespaces to objects while (includes[++i]) { includes[i] = cache[includes[i]]; } cache[namespace] = callback.apply(null, includes); } function require(includes, callback) { var i = -1; // convert string namespaces to objects while (includes[++i]) { includes[i] = cache[includes[i]]; } callback.apply(null, includes); } define('Library.util.add', function() { function add(a, b) { return a + b; } return add; }); define('Library.cool.Class', ['Library.util.add'], function(add) { function Class(startValue) { this.value = startValue; } Class.prototype = { 'addToValue': function(value) { this.value = add(this.value, value); } }; return Class; }); var Klass; require(['Library.cool.Class'], function(Class) { Klass = Class; }); }; ui.benchmarks[2].setup = ui.benchmarks[1].setup; </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 (new Library.cool.Class(1)).addToValue(1); Test 2 Title Async (check if this is an asynchronous test) Code (new Klass(1)).addToValue(1); Test 3 Title Async (check if this is an asynchronous test) Code require(['Library.cool.Class'], function(Class) { (new Class(1)).addToValue(1); });