jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase .
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2 Can be accessed at:
https://jsperf.app/negative-modulo/2 Property Getter / Setter Techniques (v7) Revision 7 of this benchmark created by Scott Wolchok on August 27, 2011 Description Testing various techniques for creating getters / setters in JavaScript. This revision uses actual prototype-based classes where possible; seems to result in a significant speedup for the method-based version.
Preparation HTML <script >
function BareProperty ( ) {
this .prop = 0 ;
}
function GetterAndSetter ( ) {
this ._prop = 0 ;
}
GetterAndSetter .prototype .getProp = function ( ) {
return this ._prop ;
};
GetterAndSetter .prototype .setProp = function (value ) {
this ._prop = value;
};
function GetSet ( ) {
this ._prop = 0 ;
}
GetSet .prototype = {
get prop () {
return this ._prop ;
}, set prop (value ) {
this ._prop = value;
},
};
function DefineProperty ( ) {
this ._prop = 0 ;
Object .defineProperty (this , "prop" , {
get : function ( ) {
return this ._prop ;
},
set : function (val ) {
this ._prop = val;
}
});
}
function DefineGetterSetter ( ) {
this ._prop = 0 ;
this .__defineGetter__ ("prop" , function ( ) {
return this ._prop ;
});
this .__defineSetter__ ("prop" , function (val ) {
this ._prop = val;
});
}
</script >
Setup var obj = new BareProperty ();
var obj1 = new GetterAndSetter ();
var obj2 = new GetSet ();
var obj3 = new DefineProperty ();
var obj4 = new DefineGetterSetter ();
Test runner Ready to run.
Run Quick Run Testing in Test Ops/sec Methods obj1.setProp (obj1.getProp () + 1 );
ready
get / set obj2.prop = obj2.prop + 1 ;
ready
Object.defineProperty obj3.prop = obj3.prop + 1 ;
ready
__defineGetter__ obj4.prop = obj4.prop + 1 ;
ready
Property obj.prop = obj.prop + 1 ;
ready
Revisions You can edit these tests or add more tests to this page by appending /edit to the URL.
Revision 1 : published by Mike Chambers on February 18, 2011 Revision 3 : published by Miller Medeiros on February 18, 2011 Revision 6 : published on July 30, 2011 Revision 7 : published by Scott Wolchok on August 27, 2011 Revision 8 : published by john on September 17, 2011 Revision 10 : published on September 23, 2011 Revision 11 : published by Stéphan Kochen on October 6, 2011 Revision 12 : published on October 13, 2011 Revision 14 : published by Elijah Insua on October 16, 2011 Revision 16 : published on November 7, 2011 Revision 18 : published on November 30, 2011 Revision 19 : published by Andrew Petersen on December 19, 2011 Revision 20 : published on January 10, 2012 Revision 21 : published on February 19, 2012 Revision 22 : published by ppold on February 20, 2012 Revision 23 : published by ppold on February 20, 2012 Revision 24 : published on May 13, 2012 Revision 25 : published on May 27, 2012 Revision 26 : published on September 11, 2012 Revision 27 : published on September 26, 2012 Revision 28 : published on October 31, 2012 Revision 29 : published by nobuoka on November 27, 2012 Revision 31 : published by Adrian Vogelsgesang on December 21, 2012 Revision 32 : published on February 27, 2013 Revision 33 : published on March 4, 2013 Revision 60 : published on May 2, 2013 Revision 61 : published on May 10, 2013 Revision 62 : published on June 6, 2013 Revision 63 : published on July 31, 2013 Revision 64 : published on July 31, 2013 Revision 65 : published on August 9, 2013 Revision 66 : published on August 14, 2013 Revision 67 : published by sportebois on September 9, 2013 Revision 68 : published on September 23, 2013 Revision 70 : published on October 17, 2013 Revision 72 : published on January 24, 2014 Revision 73 : published on January 30, 2014 Revision 74 : published on February 20, 2014 Revision 75 : published by Jon-Carlos Rivera on February 23, 2014 Revision 76 : published on February 28, 2014 Revision 77 : published on March 10, 2014 Revision 79 : published by Stanislav on May 1, 2014 Revision 81 : published on August 29, 2014 Revision 84 : published by kon on September 23, 2014 Revision 85 : published by Joshua Wise on October 22, 2014 Revision 86 : published on November 11, 2014 Revision 87 : published on December 1, 2014 Revision 88 : published by Joshua Wise on January 5, 2015 Revision 89 : published on January 7, 2015 Revision 90 : published by DB on January 20, 2015 Revision 92 : published on February 4, 2015 Revision 93 : published on February 6, 2015 Revision 94 : published by madreason on February 6, 2015 Revision 96 : published on April 15, 2025