Script Preparation code:
AخA
 
var path = '/foo/bar';
Tests:
  • Split

     
    var pathFields = path.split('/');
    if (pathFields.length > 0) {
      var pathRoot = pathFields[path.startsWith('/') ? 1 : 0];
    }
  • Regex

     
    var pathMatch = path.match(/[a-z]+(?=\/)/);
    if (pathMatch) {
      var pathRoot = pathMatch[0];
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Split
    Regex

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0
Firefox 84 on Windows
View result in a separate tab
Test name Executions per second
Split 7244177.0 Ops/sec
Regex 17566646.0 Ops/sec