Created
September 23, 2012 20:26
-
-
Save briancavalier/3772938 to your computer and use it in GitHub Desktop.
Object.freeze() perf hit in v8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A simple test to show the perf difference between property access | |
// in non-frozen, and frozen objects in v8 | |
// `node freeze-perf.js` | |
var o1, o2, key, start; | |
o1 = {a: 1}; | |
o2 = Object.freeze({a: 1}); | |
start = Date.now(); | |
for(var i=0; i<100000; i++) { | |
for(key in o1) o1[key] = i; | |
} | |
console.log(Date.now() - start); | |
start = Date.now(); | |
for(i=0; i<100000; i++) { | |
for(key in o2) o2[key] = i; | |
} | |
console.log(Date.now() - start); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A simple test to show the perf difference between property access | |
// in non-frozen, and frozen objects in v8 | |
// `node freeze-perf2.js` | |
var o1, o2, start; | |
o1 = {a: 1}; | |
o2 = Object.freeze({a: 1}); | |
start = Date.now(); | |
for(var i=0; i<1000000; i++) { | |
o1.a = i; | |
} | |
console.log(Date.now() - start); | |
start = Date.now(); | |
for(i=0; i<1000000; i++) { | |
o2.a = i; | |
} | |
console.log(Date.now() - start); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment