RegExp test / search / match vs. indexOf / substr

JavaScript performance comparison

Revision 75 of this test case created by

Preparation code

<script>

var str = 'Heya, Hiya, Hello, world.',
	q = 'Hell',
  qUpper = 'HELL',
	re = /hell/i;

</script>
    

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
test
/hell/i.test(str);
pending…
search
str.toUpperCase().search(qUpper) > -1;
pending…
match
str.match(q).length > 0;
pending…
indexOf
str.toUpperCase().indexOf(qUpper) === 0;
pending…
lastIndexOf
str.toUpperCase().lastIndexOf(qUpper, 0) === 0;
pending…
precompiled test
re.test(str);
pending…
precomiled search
str.search(re) !== -1;
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