Prototype vs Non-Prototype

Benchmark created by Jeremy McPeak (Nettuts) 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>

Test runner

Ready to run.

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

Revisions

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