Script Preparation code:
x
 
var cnt = 500 * 1024;
var str = []
for(var i=0; i < cnt; i++) {
  str.push( String.fromCharCode(Math.random() * 94 + 32) );
}
str = str.join("");
var regex = function(count) {
  var rgx = new RegExp("[\\s\\S]{1," + count + "}", "g");
  var parts = str.match(rgx);
};
var slice = function(count) {
  var parts = [];
  for(var i = 0, len = str.length; i < len; i += count) {
    parts.push( str.slice(i, i + count) );
  }
};
var substr = function(count) {
  var parts = [];
  for(var i = 0, len = str.length; i < len; i += count) {
    parts.push( str.substr(i, count) );
  }
};
Tests:
  • Testing Regex, Length 1

     
    regex(1);
  • Testing Regex, Length 10

     
    regex(10);
  • Testing Regex, Length 100

     
    regex(100);
  • Testing Regex, Length 9 kB

     
    regex(9 * 1024);
  • Testing Slice, Length 1

     
    slice(1);
  • Testing Slice, Length 10

     
    slice(10);
  • Testing Slice, Length 100

     
    slice(100);
  • Testing Slice, Length 9 kB

     
    slice(9 * 1024);
  • Testing Substr, Length 1

     
    substr(1);
  • Testing Substr, Length 10

     
    substr(10);
  • Testing Substr, Length 100

     
    substr(100);
  • Testing Substr, Length 9 kB

     
    substr(9 * 1024);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Testing Regex, Length 1
    Testing Regex, Length 10
    Testing Regex, Length 100
    Testing Regex, Length 9 kB
    Testing Slice, Length 1
    Testing Slice, Length 10
    Testing Slice, Length 100
    Testing Slice, Length 9 kB
    Testing Substr, Length 1
    Testing Substr, Length 10
    Testing Substr, Length 100
    Testing Substr, Length 9 kB

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0
Firefox 93 on Windows
View result in a separate tab
Test name Executions per second
Testing Regex, Length 1 38.7 Ops/sec
Testing Regex, Length 10 99.3 Ops/sec
Testing Regex, Length 100 586.4 Ops/sec
Testing Regex, Length 9 kB 567.7 Ops/sec
Testing Slice, Length 1 35.9 Ops/sec
Testing Slice, Length 10 402.4 Ops/sec
Testing Slice, Length 100 5782.4 Ops/sec
Testing Slice, Length 9 kB 553193.5 Ops/sec
Testing Substr, Length 1 36.4 Ops/sec
Testing Substr, Length 10 419.0 Ops/sec
Testing Substr, Length 100 5530.7 Ops/sec
Testing Substr, Length 9 kB 709876.9 Ops/sec