JS Search vs Lunr JS - Running Queries

JavaScript performance comparison

Revision 5 of this test case created by Brian Vaughn

Preparation code

<script type="text/javascript" src="https://rawgit.com/olivernn/lunr.js/master/lunr.js"></script>
<script type="text/javascript" src="https://rawgit.com/bvaughn/js-search/1.2.0/dist/js-search.js"></script>

      
<script>
Benchmark.prototype.setup = function() {
  var books = [];
  var xmlhttp = new XMLHttpRequest();
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      var json = JSON.parse(xmlhttp.responseText);
  
      books = json.books;
    }
  }
  xmlhttp.open('GET', 'http://bvaughn.github.io/js-search/books.json', true);
  xmlhttp.send();
  
  var search = new JsSearch.Search('isbn');
  search.searchIndex = new JsSearch.UnorderedSearchIndex();
  search.addIndex('title');
  search.addIndex('author');
  search.addDocuments(books);
  
  var searchTfIdf = new JsSearch.Search('isbn');
  searchTfIdf.searchIndex = new JsSearch.TfIdfSearchIndex('isbn');
  searchTfIdf.addIndex('title');
  searchTfIdf.addIndex('author');
  searchTfIdf.addDocuments(books);
  
  var lunrJsIndex = new lunr.Index
  lunrJsIndex.field('title');
  lunrJsIndex.field('author');
  lunrJsIndex.ref('isbn');
  
  for (var i = 0, length = books.length; i < length; i++) {
    lunrJsIndex.add(books[i]);
  }
  
  var searchTerms = ['letter', 'world', 'wife', 'love', 'foobar'];

};
</script>

Preparation code output

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
Lunr JS: Running searches
for (var i = 0, length = searchTerms.length; i < length; i++) {
  lunrJsIndex.search(searchTerms[i]);
}
pending…
JS Search: Running searches (TF-IDF enabled)
for (var i = 0, length = searchTerms.length; i < length; i++) {
  searchTfIdf.search(searchTerms[i]);
}
pending…
JS Search: Running searches (TF-IDF disabled)
for (var i = 0, length = searchTerms.length; i < length; i++) {
  search.search(searchTerms[i]);
}
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