forEach

JavaScript performance comparison

Test case created by GO-gyan

Preparation code

<script>
const employee = [
  { 
    companyName: "xyz.com",
    age: 26,
    role: "Software Engineer",
    salary: 35000,
    timeSpent: 3
  },
  {
    companyName: "My Traveler",
    age: 28,
    role: "Senior Software Engineer",
    salary: 65000,
    timeSpent: 2
  },
  {
    companyName: "Product Wheel",
    age: 31,
    role: "Lead Engineer",
    salary: 90000,
    timeSpent: 3
  },
  {
    companyName: "Make My Budget",
    age: 35,
    role: "Consultant",
    salary: 125000,
    timeSpent: 4
  },
];
</script>
    

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
for loop
const companies = [];
for(i=0; i < employee.length; i++) {
  const company = employee[i].companyName;
  companies.push(company);
}
pending…
forEach
const companies = [];
function getCompaniesName(emp) {
  const company = emp.companyName;
  companies.push(company);
}
employee.forEach(getCompaniesName);
pending…
map
const companies = employee.map(emp => emp.companyName);
pending…

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

Compare results of other browsers

0 Comments