Slice vs Substr vs Substring Methods

JavaScript performance comparison

Revision 2 of this test case created


This is comparing the runtimes of substr, substring, and slice in a string for large (10000 character) string size.

Preparation code

  var longString = "";
  // Large = 10,000
  for (var i = 0; i < 10000; i++) {
        longString += i % 10;

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Substring (long)
for (i = 0; i < longString.length; i++) {
  longString.substring(i, i+1);
Slice (long)
for (i = 0; i < longString.length; i++) {
  longString.slice(i, i + 1);
Substr (long)
for (i = 0; i < longString.length; i++) {
  longString.substr(i, 1);

Compare results of other browsers


You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:


Comment form temporarily disabled.

Add a comment