Re:Node.js Guide
by swannodette on Thursday March 31, 2011 @01:25PM
(#2392541)
http://jsperf.com/object-freeze/3
http://jsperf.com/object-freeze/5
http://jsperf.com/object-freeze/6
A reminder on how immutable objects are meant to be used. When used properly even under attempts to mutate, they run circles around trying to use mutable objects in an immutable manner.
Yeah, I did something stupid in my own test. Probably I was thinking about Object.seal(). Nevertheless your own test revision #3 shows that accesses to frozen properties are roughly 14 times slower.
Revisions #5 and #6 do an allocation in the "hot" testcase so the real cost of property lookup just becomes hidden behind cost of memory management.
See http://jsperf.com/object-freeze results.