Prototype vs Non-Prototype (v2)

Revision 2 of this benchmark created on


Description

Testing the difference in execution time of creating objects using the prototype and not using it.

Preparation HTML

<script>
  function Person(firstName, lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
  }
  
  Person.prototype.getFullName = function() {
    return this.firstName + " " + this.lastName;
  };
  
  function Person2(firstName, lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.getFullName = function() {
      return this.firstName + " " + this.lastName;
    };
  }
</script>
<span id="t1"></span> - <span id="t2"></span>

Setup

var name;
    var name2;

Teardown


    var t1 = document.getElementById('t1');
    var t2 = document.getElementById('t2');
    
    t1.innerHTML = name;
    t2.innerHTML = name2;
  

Test runner

Ready to run.

Testing in
TestOps/sec
Prototype
var person = new Person("Jeremy", "McPeak");
name = person.getFullName();
ready
Non-Prototype (Nested)
var person2 = new Person2("Jeremy", "McPeak");
name2 = person2.getFullName();
ready

Revisions

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