substring test short haystack

JavaScript performance comparison

Test case created

Preparation code

<script>
  var str = "This is a simple test!";
  var needle = "simple";
  var r = new RegExp('simple');
  var ri = new RegExp('simple', 'i');
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
regex
var c = /simple/.test(str)
pending…
indexof
var c = str.indexOf(needle) > -1
pending…
RegExp
var c = (new RegExp(needle)).test(str);
pending…
Cached RegExp
var c = r.test(str);
pending…
regex case insensitive
var c = /simple/i.test(str);
pending…
indexOf case insensitive
var c = str.toLowerCase().indexOf(needle) > -1;
pending…
RegExp case insensitive
var c = (new RegExp(needle, 'i')).test(str);
pending…
cached RegExp case insensitive
var c = ri.test(str);
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. Here’s a list of current revisions for this page:

0 comments

Add a comment