prototype vs closures (v63)

Revision 63 of this benchmark created on


Setup

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) {
    function get_name() {
      return name;
    }
    function set_name(newName) {
      name = newName;
    }  
    return {
      'name': name,
      'get_name': get_name,
      'set_name': set_name
    };
  };
  
  var p = new Person('John');
  var dp = Person.prototype;
  var pc = p.constructor.prototype;
  var c = person('John');

Test runner

Ready to run.

Testing in
TestOps/sec
Prototype init
p = new Person('John');
ready
Closure init
c = person('John');
ready
Prototype read
p.get_name();
ready
Prototype direct read
dp.get_name();
ready
Prototype constructor read
pc.get_name();
ready
Closure read
c.get_name();
ready
Prototype write
p.set_name('Jane');
ready
Prototype direct write
dp.set_name('Jane');
ready
Prototype constructor write
pc.set_name('Jane');
ready
Closure write
c.set_name('Jane');
ready

Revisions

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