FOR VS FIND

JavaScript performance comparison

Test case created by rise2semi

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  let currentUser;
  let users = [
      { name: 'Rinat', skills: ['JS', 'CSS', 'React'] },
      { name: 'Borys', skills: ['JS', 'CSS', 'Angular'] },
      { name: 'Pavlo', skills: ['JS', 'CSS', 'Vue'] }
  ];

};
</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
FIND + SOME
currentUser = users.find(user => user.skills.some(skill => skill === 'Angular'))
pending…
FOR
usersLoop: for (let user of users) {
    for (let skill of user.skills) {
        if (skill === 'Angular') {
            currentUser = user;
            break usersLoop;
        } 
    }
}
pending…
FIND
currentUser = users.find(user => user.skills.includes('Angular'))
pending…

Compare results of other browsers

Revisions

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

0 Comments