regexp vs indexOf

JavaScript performance comparison

Test case created by Anton Ignatov

Preparation code

<script>
var regex = /\s+/,
    eventName = 'test.a1';
</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
regexp
var events = eventName.split(regex)
pending…
indexOf
var events;

if (eventName.indexOf(' ') >= 0) {
    events = eventName.split(regex);
} else {
    events = [eventName];
}
pending…

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

Compare results of other browsers

0 comments

Add a comment