Editing How to write up to 98% faster JavaScript code. 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 shows that frameworks built on a global namespace (jQuery, YUI, Prototype, ...) ***could have been up to 98% faster*** (Firefox) if they were written in a string based modular fashion like it is used by [Compact.js](https://github.com/DominikGuzei/Compact.js) that is based on [Require.js](http://http://requirejs.org/) Please tell me wrong, I can't believe it :-) Dominik Guzei [Wizzart](http://wizzart.at) 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> (function() { var f = {}, g = Array.prototype.slice; window.define = function() { var a = arguments, d = a[0], b = null; a = g.call(a, 1); if (a.length > 1) { b = a[0]; for (var c = [], e = 0; e < b.length; e++) c[e] = f[b[e]]; b = a[1].apply(this, c) } else b = a[0](); f[d] = b }; window.require = function() { var a = arguments, d = [], b = null; a.length > 2 && (a = g.call(a, 1)); d = a[0]; b = a[1]; a = []; for (var c = 0; c < d.length; c++) a[c] = f[d[c]]; b.apply(this, a) } })(); </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 Library = window.Library = {}; /* window.Library is not mandory */ Library.util = { add: function(a, b) { return a + b; } }; Library.cool = { Class: function(startValue) { this.value = startValue; } } Library.cool.Class.prototype.addToValue = function() { var add = Library.util.add; return function(value) { this.value = add(this.value, value); }; }(); var instance = new Library.cool.Class(1); while (instance.value < 100000) { instance.addToValue(1); } Test 2 Title Async (check if this is an asynchronous test) Code define('Library.util.add', function() { return function(a, b) { return a + b; } }); define('Library.cool.Class', ['Library.util.add'], function(add) { var Class = function(startValue) { this.value = startValue; }; Class.prototype.addToValue = function(value) { this.value = add(this.value, value); }; return Class; }); require(['Library.cool.Class'], function(Class) { var instance = new Class(1); while (instance.value < 100000) { instance.addToValue(1); } });