Skip to content

Instantly share code, notes, and snippets.

@tlhunter
Created July 7, 2015 02:46
Show Gist options
  • Save tlhunter/4b32c0af44195358a66e to your computer and use it in GitHub Desktop.
Save tlhunter/4b32c0af44195358a66e to your computer and use it in GitHub Desktop.
var print = typeof print === 'function' ? print : console.log.bind(console);
function X() {
}
X.prototype.dispatch = function (obj) {
this[obj.type](obj);
};
var DEGREE = 20;
var objs = [];
for (var i = 0; i < DEGREE; i++) {
var o = { type: eval(JSON.stringify("t" + i)) }; // poor mans intern
objs.push(o);
X.prototype[o.type] = function (o) { };
}
function measure(objs) {
var x = new X();
var start = Date.now();
for (var i = 0; i < 100000; i++) {
for (var j = 0; j < objs.length; j++) {
x.dispatch(objs[j]);
}
}
var end = Date.now();
print(end - start);
}
measure(objs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment