substr_replace

JavaScript performance comparison

Test case created by Josh

Preparation code

<script>
  var replaceme = "};"
 
  function substr(str, chr) {
    var start = chr;
    var length = 1;
    var replace = "";
 
    return str.slice(0, start) + replace.substr(0, length) + replace.slice(length) + str.slice(start + length);
  }
 
  function arrmut(str, chr) {
    var arr = Array.prototype.slice.call(str, 0);
    delete arr[chr];
    return arr.join("");
  }
</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
str.slice + substr
substr(replaceme, 2);
pending…
array.prototype.slice
arrmut(replaceme, 2);
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