prototype vs closures (v76)

Revision 76 of this benchmark created by Anonymous on


Preparation HTML

<script type="application/javascript;version=1.8">
"use strict";
function Person(name) {
	this.name = name;
  const name2 = name
  this.get_name_const = function() {
    return name2
  }

}

Person.prototype.get_name_property = function() {
	return this.name;
};

var _c = [];
var i;
for (i = 0; i < 10000; ++i) {
  _c.push(new Person('John'));
}
var escape_hatch = null
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Prototype read
var i;
for (i = 0; i < _c.length; ++i) {
  escape_hatch = _c[i].get_name_property();
}
ready
Closure read
var i;
for (i = 0; i < _c.length; ++i) {
  escape_hatch = _c[i].get_name_const();
}
ready

Revisions

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