Calling public methods accessing private vars (v18)

Revision 18 of this benchmark created on


Description

Checking the performance of calling public methods with private variables.

Preparation HTML

<script>
  function ConstructorPrivateProperties() {

      var that = {};
      var privateProperty1 = 1;
  
      that.publicMethod1 = function() {
         return privateProperty1;
      };

      return that;
   }
  
  function PrototypePrivateProperties() {}
  
  PrototypePrivateProperties.prototype = {

      _privateProperty1: 1,
  
      publicMethod1: function() {
         return this._privateProperty1;
      }
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
call constructor
var instance = new ConstructorPrivateProperties();

for (var i = 0; i < 1000; i++) {
 instance.publicMethod1();
}
ready
call prototype
var instance = new PrototypePrivateProperties();

for (var i = 0; i < 1000; i++) {
 instance.publicMethod1();
}
ready

Revisions

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