slice substr substring

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var longStr = "Blue Blue  fun lorem loremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremlorem    loremloremlorem loremloremloremloremloremloremloremlorem pooper  lorem";
   
    var shortStr = "blue fun pooper lorem";
   
    var longIdx = longStr.indexOf('pooper');
    var longEndIdx = longIdx + 5;
   
    var shortIdx = shortStr.indexOf('pooper');
    var shortEndIdx = shortIdx + 5;
};
</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
long substr
longStr.substr(longIdx, 5);
pending…
long substring
longStr.substring(longIdx, longEndIdx);
pending…
long slice
longStr.slice(longIdx, longEndIdx);
pending…
short substr
shortStr.substr(shortIdx, 5);
pending…
short substring
shortStr.substring(shortIdx, shortEndIdx);
pending…
short slice
shortStr.slice(shortIdx, shortEndIdx);
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