getters and setters (v5)

Revision 5 of this benchmark created on


Description

lets try

Preparation HTML

<script>
  var test = {
   value: 1,

   getValue: function() {
    return this.value;
   },

   setValue: function(v) {
    this.value = v;
   },

   valueDefTest: function(val) {
    if (typeof val != "undefined")
        this.value = val;
    return this.value;
   },

   valueDefTestDE: function(val) {
    if (typeof val !== "undefined")
        this.value = val;
    return this.value;
   },

   valueDefTestConst: function(val) {
    if (val !== undefined)
        this.value = val;
    return this.value;
   },

   valueArgTest: function(val) {
    if (arguments.length) this.value = val;
    return this.value;
   },

   valueDefTestLocalConst: (function (undefined) {
    return function(val) {
        if (val !== undefined)
          this.value = val;
        return this.value;
     };
   })()

  };
  
  var result = 0;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
simple val
result += test.value
ready
getter
result += test.getValue();
ready
defined test
result += test.valueDefTest();
ready
arg test
result += test.valueArgTest();
ready
def test de
result += test.valueDefTestDE();
ready
def test const
result += test.valueDefTestConst();
ready
def test local const
result += test.valueDefTestLocalConst();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.