Skip to content

Instantly share code, notes, and snippets.

@mraleph
Last active April 13, 2016 14:37
Show Gist options
  • Select an option

  • Save mraleph/ad266f84047fcab654f52a6214a60663 to your computer and use it in GitHub Desktop.

Select an option

Save mraleph/ad266f84047fcab654f52a6214a60663 to your computer and use it in GitHub Desktop.
(function () {
var now = typeof performance !== 'undefined' ? performance.now.bind(performance) : Date.now;
function Accessor() {
var obj = { }
obj.x = 0;
delete obj.x;
var _a = 0;
Object.defineProperty(obj, 'a', {
enumerable: true,
get: function () { return _a; },
set: function(val) { _a = val; }
});
var sum = 0;
var start = now();
for (var i = 0; i < 1000000; i++) {
sum += obj.a;
obj.a = i;
}
var end = now();
return (end - start);
}
function KindaAccessor() {
var obj = { }
obj.x = 0;
delete obj.x;
var _a = 0;
obj.a = {
get: function () { return _a; },
set: function(val) { _a = val; }
};
var sum = 0;
var start = now();
for (var i = 0; i < 1000000; i++) {
sum += obj.a.get();
obj.a.set(i);
}
var end = now();
return (end - start);
}
for (var i = 0; i < 10; i++) {
Accessor();
KindaAccessor();
}
if (Accessor()/KindaAccessor() > 2 * Math.PI) {
alert("(ಥ﹏ಥ) this VM could handle accessors much better");
} else if (Accessor()/KindaAccessor() > Math.E) {
alert("(ಠ_ಠ) this VM could handle accessors better");
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment