Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
function SpeedComparison(testData, accuracy, methods) { if ( ! (this instanceof arguments.callee) ) { return; } this.accuracy = accuracy || 1000; this.methods = methods || {}; this.testData = testData; this.results = {}; } SpeedComparison.prototype = { addMethod : function(name, method) { this.methods[name] = method; return this; }, removeMethod : function(name) { delete this.methods[name]; return this; }, begin : function() { iterateMethods : for (var method in this.methods) { var sTime = +new Date(); for (var i = 0, a = this.accuracy; i < a; i++) { if (this.methods[method](this.testData) === false) { this.results[method] = 'Failed'; continue iterateMethods; } } var fTime = +new Date(); this.results[method] = fTime - sTime; } } }; var test = new SpeedComparison(['a','really','long','array'], 1000); // Add each method to be tested: test.methods = { 'STRING' : function(arr) { var built = []; for (var i = 0, l = arr.length; i < l; i++) { built[built.length] = '<li>' + arr[i] + '</li>'; } NN.push(built.join('')); }, 'ARRAY' : function(arr) { var list = ''; for (var i = 0, l = arr.length; i < l; i++) { list += '<li>' + arr[i] + '</li>'; } NN.push(list); }, 'JOIN()' : function(arr){ NN.push(arr.join('</li><li>')); } }; // Log results log(test.results); // Assert all methods worked as expected: log(NN[0] === NN[1] && NN[1] === NN[2]);
This paste will be private.
From the Design Piracy series on my blog: