Initial char (v25)

Revision 25 of this benchmark created on


Preparation HTML

<script>
  var needle = "This is the string you search!";
  var str = (Math.random() >= 0.5 
             ? needle
             : "This is not the string you search!");

  var r = new RegExp('^' + needle + '$');
  var ri = new RegExp('^' + needle + '$', 'i');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
regex
var c = /^This is the string you search!$/.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 = /^This is the string you search!$/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

Revisions

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