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);
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(test.results);
log(NN[0] === NN[1] && NN[1] === NN[2]);