find vs indexof (v2)

Revision 2 of this benchmark created by abacb on


Setup

'use strict';
    
    var board = [['red', 'red', 'red'], ['red', 'red', 'red'], ['red', 'green', 'red']];

Test runner

Ready to run.

Testing in
TestOps/sec
find
board.find(function (row) {
  return row.find(function (cell) {
    return cell === 'green' && console.log('found a green cell') && true;
  });
}) || false;
ready
indexof
board.toString().indexOf("green") > -1
ready
nobreak
// Generated by LiveScript 1.2.0
var i$, ref$, len$, yet$, row, j$, len1$, cell;
outer: for (yet$ = true, i$ = 0, len$ = (ref$ = board).length; i$ < len$; ++i$) {
  row = ref$[i$];
  for (j$ = 0, len1$ = row.length; j$ < len1$; ++j$) {
    cell = row[j$];
    if (cell === 'green') {
      console.log('found a green cell');
      yet$ = false; break outer;
    }
  }
} if (yet$) {
  console.log('could not find green cell');
}
ready

Revisions

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