substring test short haystack (v13)

Revision 13 of this benchmark created on


Preparation HTML

<script>
  var str = "abstract event new struct as explicit null switch base extern object this bool false operator throw break finally out true byte fixed override try case float params typeof catch for private uint char foreach protected ulong checked goto public unchecked class if readonly unsafe const implicit ref ushort continue in return using decimal int sbyte virtual default interface sealed volatile delegate internal short void do is sizeof while double lock stackalloc else long static enum namespace string";
  var needle = "public";
  var r = new RegExp('public');
  var ri = new RegExp('public', 'i');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
regex
var c = /simple/.test(str)
ready
indexof
var c = str.indexOf(needle) > -1
ready
RegExp
var c = (new RegExp(needle)).test(str);
ready
Cached RegExp
var c = r.test(str);
ready
regex case insensitive
var c = /simple/i.test(str);
ready
indexOf case insensitive
var c = str.toLowerCase().indexOf(needle) > -1;
ready
RegExp case insensitive
var c = (new RegExp(needle, 'i')).test(str);
ready
cached RegExp case insensitive
var c = ri.test(str);
ready
split
var c = str.split(needle).length > 1;
ready

Revisions

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