string split join

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    // We need the fastest way to to remove the last part of the string,
    // after the last "."
    var string = 'a.b.c.d'
};
</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, slice, join
string.split('.').slice(0, -1).join('');
pending…
split, slice, join
var s_split = string.split('.'),
    s_len = s_split.length;

s_split.slice(0, s_len - 1).join('');
pending…
slice, lastIndexOf
string.slice(0, string.lastIndexOf('.'))
pending…
substring, lastIndexOf
string.substring(0, string.lastIndexOf('.'))
pending…
substr, lastIndexOf
string.substr(0, string.lastIndexOf('.'))
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