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

Revision 103 of this benchmark created on


Setup

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';

Test runner

Ready to run.

Testing in
TestOps/sec
Substring
str1.substring(1, 3);
str2.substring(2, 3);
str3.substring(5);
ready
Substr
str1.substr(1, 2);
str2.substr(2, 1);
str3.substr(5);
ready
Slice
str1.slice(1, 3);
str2.slice(2, 3);
str3.slice(5);
ready
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);
ready
ParseInt
parseInt(num1);
parseInt(num2);
parseInt(num3);
ready
Bitwise Substring
~~num1.substring(0,2);
~~num2.substring(0,2);
~~num3.substring(0,2);
ready
Bitwise CharAt
~~(num1.charAt(0)+num1.charAt(1))
~~(num2.charAt(0)+num2.charAt(1))
~~(num3.charAt(0)+num3.charAt(1))
ready

Revisions

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