Skip to content

Instantly share code, notes, and snippets.

@hns
Created August 19, 2011 14:29
Show Gist options
  • Save hns/1156928 to your computer and use it in GitHub Desktop.
Save hns/1156928 to your computer and use it in GitHub Desktop.
JS property read/write micro benchmark
function bench(x) {
for (var i = 0; i < 10000000; i++) {
x.foo = x.baz;
x.bar = x.mur;
x.dng = x.foo;
x.baz = x.bar;
x.mur = x.dng;
}
}
if (typeof console === "undefined") console = {log: print};
var obj = {
foo: "foo",
bar: "bar",
dng: "dng",
baz: "baz",
mur: "mur"
};
for (var k = 0; k < 10; k++) {
var start = new Date().getTime();
bench(obj);
console.log(new Date().getTime() - start);
}
console.log(JSON.stringify(obj));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment