Quick comment first: You are running all of this on objects in global scope which will mess up the results considerably. Running this inside a non global scope should almost eliminate the difference between the property and method access times, but the method might still be slightly faster since we will create optimized code for the two methods, whereas we will still use ICs for the property load and store.
As your numbers suggest there is no difference in the access times no matter how you declare accessors on the objects (except when you create them by hand using methods), but the difference to methods seems unreasonably high (I get 50X running in function scope), I will take a closer look at this. I filled http://code.google.com/p/v8/issues/detail?id=1693 to track this. Cheers, Rico On Thu, Sep 15, 2011 at 7:46 PM, ohnnyj <[email protected]> wrote: > Hello all: > > I am in the process of building a UI framework in JS using ECMA5 > whenever possible. I love the new Object.create and > Object.defineProperty syntax with the ability to cleanly add accessor > methods. > > I have been doing some profiling of various accessor techniques and > have consistently found Object.defineProperty to be much slower than > property syntax and normal function definitions. For reference please > see: > > http://jsperf.com/getter-setter/6 > > This isn't a small difference, on my machine I was getting something > like 230 million ops/s vs 1.4 million ops/s. I have done further > tests to get a sense of real world usage. For example, I have created > a WebGL animation library and toggled between using functions and > properties defined with defineProperty: > > object.getX() / object.setX() > > vs > > object.x > > As the number of objects increases the property syntax shows a clear > decrease in performance over the function calls, somewhere in the > range of 6 to 10 fps. > > I am not sure this is due to the perhaps v8 (and in general all JS > engines) being optimized for function syntax over ECMA5 syntax or > perhaps the extra baggage that comes with the latter, namely the > writable, configurable, and enumerable attributes. > > Just curious if I am the only one who has seen this. > > Thanks. > > -- > v8-users mailing list > [email protected] > http://groups.google.com/group/v8-users > -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
