prototypal vs closure calls

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function PrototypalPerson() {}
    PrototypalPerson.prototype.setName = function setName(name) {
      this.name = name;
    };
    PrototypalPerson.prototype.getName = function getName() {
      return this.name;
    };
    var prototypalPerson = new PrototypalPerson();
   
   
    function newClosurePerson() {
      var name = undefined;
   
      function getName() {
        return name;
      }
   
      function setName(_name) {
        name = _name;
      }
      return Object.freeze({
        setName: setName,
        getName: getName
      });
    }
    var closurePerson = newClosurePerson();
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Prototypal
prototypalPerson.setName('john');
prototypalPerson.getName();
pending…
Closure
closurePerson.setName('john');
closurePerson.getName();
pending…

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

Compare results of other browsers

0 comments

Add a comment