prototype vs closures

JavaScript performance comparison

Revision 54 of this test case created by Dillon Uzar

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function get_name() {
    return this.name;
  }
  
  function set_name(name) {
    this.name = name;
  }
  
  function Person(name) {
    this.name = name;
  }
  Person.prototype.get_name = get_name;
  Person.prototype.set_name = set_name;
  
  var person = function(name) {
    return {
      'name': name,
      'get_name': get_name,
      'set_name': set_name
    };
  };
  
  var p = new Person('John');
  var c = person('John');

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Prototype init
p = new Person('John');
pending…
Closure init
c = person('John');
pending…
Prototype read
p.get_name();
pending…
Closure read
c.get_name();
pending…
Prototype write
p.set_name('Jane');
pending…
Closure write
c.set_name('Jane');
pending…

Compare results of other browsers

Revisions

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

0 Comments