regexp test vs indexOf

JavaScript performance comparison

Revision 129 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var str = "hello world!";
    var reg = /world/;
   
    var browserSelect1 = function() {
        // select correct chrome.tabs.query object based on browser
        if (/(Google)/i.test(window.navigator.vendor)) {
            return {"active": true, "currentWindow": true};
        }
        if (/(Opera)/i.test(window.navigator.vendor)) {
            return {"active": true, "windowType": "normal"};
        }
    };
   
    var browserSelect2 = function() {
        // select correct chrome.tabs.query object based on browser
        if (window.navigator.vendor.indexOf("Google") === 0) {
            return {"active": true, "currentWindow": true};
        }
        if (window.navigator.vendor.indexOf("Opera") === 0) {
            return {"active": true, "windowType": "normal"};
        }
    };
};

Benchmark.prototype.teardown = function() {
    browser = undefined;
};
</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
browserSelect1();
pending…
indexOf
browserSelect1();
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