Skip to content

Instantly share code, notes, and snippets.

@Constellation
Created February 3, 2011 06:51
Show Gist options
  • Save Constellation/809138 to your computer and use it in GitHub Desktop.
Save Constellation/809138 to your computer and use it in GitHub Desktop.
function bench(c, func) {
var d = Date.now();
try {
func();
} catch(e) {
print(e);
}
print(c + " : " + (Date.now() - d));
}
bench('pure', function() {
var ary = [];
ary.length = (1 << 24) - 1;
ary.length = 0;
});
bench('tainted', function() {
"use strict";
var ary = [];
Object.defineProperty(ary, '0', { value: "OK" });
ary.length = (1 << 24) - 1;
ary.length = 1;
// ary.length = 0;
});
bench('tainted2', function() {
"use strict";
var ary = [];
Object.defineProperty(ary, '0', {
enumerable: true,
configurable: true,
writable: true,
value: "OK"
});
ary.length = (1 << 24) - 1;
ary.length = 1;
// ary.length = 0;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment