split

JavaScript performance comparison

Test case created by Bruno

Info

Split a string to retrieve number at beginning

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    str = "1000: rest of string";
};
</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
split
str.split(":")[0];
pending…
regex1
str.replace(/^(\d+):.+$/, '$1');
pending…
substring
str.substring(0, str.indexOf(":"))
pending…
substring_search
str.substring(0,str.search(':'))
pending…
regex2
str.match( /\d+/ig);
pending…
regex_3
str.match(/^(\d*):\s/)[1]
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