Strings checking for substring at start

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var bigOldStringToTest = "ntuahlrceothunhnaeohutnaheontmjsnthskmq;snhksnt;heontmasntoehunstahtheosntuhtmkjrcrakmrlmeorcauhmrc.,jmercahuorcjkbhaurckhaeorckacp.,krmacp.bhrc.abimorc.ubeomjrackbme.rcjhar.,cuheorcahrcuhra.,cmjlchasnteohsnatjmsnohues;rcho.rcomurc;ao.hp0932gh4843chymasntom;l8roe.hplrcpj gmj'''98mauul'a8g. .8aug;lrc ;cg lagl.,. gla8,ggp9a8;hpu s;hob;kmkvwbqdkllbu;vmantoeumm ;mteha. aht;vteuhscuasnh.r,pchuasnthu;snto.hplrca,.amsucuohrs;tceouha/r.,usa .unthlua c.ogrca,.gprcah.usach.,pr rahscehu sancsrua houcah ocuehaso hueocuah oeusca .ourcahounasthsecnal.,ht nuah nhuheontahoeu scansnthoercuh accoeruchsaoceunhns ach chsanteoh crohasuntoueha ehaschoesuntha h scahoteu htoahosntueh ntashsotue as sontheunahoeusntahosecnuthsam.uasorceh usc",
    stringWeWant = 'ntuahlrceothunhnaeohutna',
    regexWeWant = /^ntuahlrceothunhnaeohutna/;
   
    function checkWithIndexOf( str ) {
        return str.indexOf( stringWeWant ) !== -1;
    }
   
    function checkWithRegex( str ) {
        return str.match( regexWeWant ) !== null;
    }
};
</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
indexOf
checkWithIndexOf( bigOldStringToTest );
pending…
Regex
checkWithRegex( bigOldStringToTest );
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