Script Preparation code:
x
 
// Array to hold the generated user data
var users = [];
// Function to generate random user data
function generateUserData() {
  const names = ['John', 'Jane', 'Mike', 'Emily', 'David', 'Sarah', 'Chris', 'Jessica', 'Mark', 'Lisa'];
  const lastNames = ['Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Miller', 'Davis', 'Garcia', 'Rodriguez', 'Wilson'];
  const cities = ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix', 'Philadelphia', 'San Antonio', 'San Diego', 'Dallas', 'San Jose'];
  
  const name = names[Math.floor(Math.random() * names.length)];
  const lastName = lastNames[Math.floor(Math.random() * lastNames.length)];
  const age = Math.floor(Math.random() * 60) + 18; // Random age between 18 and 77
  const city = cities[Math.floor(Math.random() * cities.length)];
  
  return {
    name,
    lastName,
    age,
    city,
  };
}
for (let i = 0; i < 500; i++) {
  const user = generateUserData();
  users.push(user);
}
Tests:
  • indexOf

     
    const usersInSanCities = users.filter(user => user.city.indexOf('San') === 0)
  • startsWith

     
    const usersInSanCities = users.filter(user => user.city.startsWith('San'))
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    indexOf
    startsWith

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36
Chrome 113 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
indexOf 148867.5 Ops/sec
startsWith 521624.7 Ops/sec