Slice vs Substr vs Substring Methods short length (10) string

JavaScript performance comparison

Revision 103 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var str1 = 'A0255AsdWW';
  var str2 = '84FdG54DfD';
  var str3 = 'c854SSD8SD';
  var num1 = '1 NOTE sdgsdnksfnsjkdaNb hsgfsjbsfn';
  var num2 = '99 OCCU d5g8dgjsvggfsg \r\nghfhdbdhda3ffhgsfvx';
  var num3 = '7 CHAR hfsfsdhfghhsgfgdgfsffg';

};
</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
str1.substring(1, 3);
str2.substring(2, 3);
str3.substring(5);
pending…
Substr
str1.substr(1, 2);
str2.substr(2, 1);
str3.substr(5);
pending…
Slice
str1.slice(1, 3);
str2.slice(2, 3);
str3.slice(5);
pending…
CharAt
str1.charAt(1) + str1.charAt(2);
str2.charAt(2);
str3.charAt(5) + str3.charAt(6) + str3.charAt(7) + str3.charAt(8) + str3.charAt(9);
pending…
ParseInt
parseInt(num1);
parseInt(num2);
parseInt(num3);
pending…
Bitwise Substring
~~num1.substring(0,2);
~~num2.substring(0,2);
~~num3.substring(0,2);
pending…
Bitwise CharAt
~~(num1.charAt(0)+num1.charAt(1))
~~(num2.charAt(0)+num2.charAt(1))
~~(num3.charAt(0)+num3.charAt(1))
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