Slice vs Substr vs Substring vs [ ] Methods

JavaScript performance comparison

Revision 111 of this test case created by hin

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var str = Array.apply(null, Array(100)).map (() => String.fromCharCode(Math.round(Math.random() * 100) % 96 + 32)).join('');
  
  var key = String.fromCharCode(Math.round(Math.random() * 100) % 96 + 32);

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Substring
str.substring(str.indexOf(key));
pending…
substr
str.substr(str.indexOf(key));
pending…
slice
str.slice(str.indexOf(key));
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments