ES6 Class vs Constructor Function

JavaScript performance comparison

Test case created by

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
ES6 Class
class Employee {
    constructor(name, job, weeklyPay, age) {
      this.name = name;
      this.job = job;
      this.weeklyPay = weeklyPay;
      this.age = age;
    }
    pay() {
        console.log(this.name + ": was paid " + this.weeklyPay);
    }
}

class Manager extends Employee {
    constructor(name, job, weeklyPay, age) {
        super(name, job, weeklyPay, age);
        this.reports=[];
    }
    addReport(report) {
        this.report.push(report);
    }

    removeReport(index) {
        this.report.splice(index,1);
    }
}

new Manager("John Smith", "Telling people what to do", "a lot", 40)
pending…
Constructor Function
function Employee(name, job, weeklyPay, age) {
    this.name = name;
    this.job = job;
    this.weeklyPay = weeklyPay;
    this.age = age;
}
Employee.prototype.pay = function() {
    console.log(this.name + ": was paid " + this.weeklyPay);
}

function Manager(name, job, weeklyPay, age) {
    Employee.call(this, name, job, weeklyPay, age);
    this.reports = [];
}
Manager.prototype = Object.create(Employee.prototype);

Manager.prototype.addReport = function(report) {
    this.reports.push(report);
}
Manager.prototype.removeReport = function(index) {
    this.reports.splice(index, 1);
}

new Manager("John Smith", "Telling people what to do", "a lot", 40)
pending…

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

0 Comments