Search Filter

Benchmark created on


Preparation HTML

<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>

Setup

var test = [{
      id: 2,
      title: "January Term in Rome",
      slug: "",
      is_live: false,
      updated_at: "2015-03-24 21:17:35",
      created_at: "2015-03-23 23:08:03",
      deleted_at: null,
      categories: []
    }, {
      id: 6,
      title: "Intern in Rome",
      slug: "",
      is_live: false,
      updated_at: "2015-03-24 21:17:35",
      created_at: "2015-03-24 21:06:18",
      deleted_at: null,
      categories: []
    }]
    
    var search = 'Intern';

Test runner

Ready to run.

Testing in
TestOps/sec
Using JSON.stringify
doFilter = function(element) {
  return _(element).toString().toLowerCase().indexOf(search.toLowerCase()) > -1
}

var results = test.filter(doFilter);
ready
Using for loop
doFilter = function(element) {
  for (var key in element) {
    if (typeof element[key] !== 'number') {
      if ((element[key] + '').toLowerCase().indexOf(search.toLowerCase()) > -1) {
        return true;
      }
    }
  }
  return false;
}

var results = test.filter(doFilter);
ready

Revisions

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