regex vs lodash contains (v3)

Revision 3 of this benchmark created by Ulises on


Preparation HTML

<script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>

Setup

var arr = ['ABC', 'QER', 'CDB', 'GBD'],
      reg = new RegExp('^(?:' + arr.join('|') + ')$');
    
    function regEx(str) {
      return reg.test(str);
    }
    
    function usingContains(str) {
      return _.contains(arr, str);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
regex
regEx('ABC');
ready
using contains
usingContains('ABC');
ready

Revisions

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

  • Revision 1: published by regex vs _.contains on
  • Revision 2: published on
  • Revision 3: published by Ulises on
  • Revision 4: published by pnoc on