slice vs subtr vs substring

JavaScript performance comparison

Test case created by bfricka

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var str = "abcdefghijklmnopqrstuvwxyz";
    var last5;
};

Benchmark.prototype.teardown = function() {
    str = last5 = 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
slice negative
last5 = str.slice(-5);
pending…
substr negative
last5 = str.substr(-5);
pending…
substring negative
last5 = str.substring(str.length - 5);
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