HTML Preparation code:
AخA
 
1
var string = "passw)odas4gsdfsdf";
Script Preparation code:
 
var string = "aaaaabbbbbccccddd";
Tests:
  • RegEx

     
    var s = string.match(/([a-zA-Z])\1*/g)||[];
    return s.map(function(itm){
      return [itm.charAt(0), itm.length];
    });
  • For Loop

     
    var result = [[string[0], 1]]
    for(let i = 1; i < string.length; i++) {
      const char = string[i]
      const lastChar = result.at(-1)
      
      if(char === lastChar[0]){
        lastChar[1] = lastChar[1] + 1
      } else {
        result.push([char, 1])
      }
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    RegEx
    For Loop

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36
Chrome 102 on Windows
View result in a separate tab
Test name Executions per second
RegEx 2541434.5 Ops/sec
For Loop 273720.7 Ops/sec