HTML Preparation code:
AخA
 
1
<div></div>
Script Preparation code:
x
 
var data = window.data = [];
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.";
var TOTAL_STRINGS = window.TOTAL_STRINGS = 100000;
function getRandomInt(max) {
    return Math.floor(Math.random() * max);
}
function makeRandomString(len) {
    var text = "";
    for (var i = 0; i < len; i++) {
        text += possible.charAt(getRandomInt(possible.length));
    }
    return text;
}
function makeRandomUrl(len) {
    var url = "file:///";
    for (var i = 0; i < len; i++) {
        url += makeRandomString(5 + getRandomInt(10));
        if (getRandomInt(2)) {
            url += "/";
        }
    }
    return url;
}
while (data.length < TOTAL_STRINGS) {
    data.push(makeRandomUrl(getRandomInt(10)));
}
Tests:
  • regex replace normalize

     
    var x = 0;
    var TOTAL_STRINGS = window.TOTAL_STRINGS;
    var data = window.data;
    while (x < TOTAL_STRINGS) {
      const str = data[x];
      const url = str.replace(/\/?$/, '');
      x += 1;
    }
  • endsWith slice normalize

     
    var x = 0;
    var TOTAL_STRINGS = window.TOTAL_STRINGS;
    var data = window.data;
    while (x < TOTAL_STRINGS) {
      const str = data[x];
      const url = str.endsWith("/") ? str.slice(0, -1) : str;
      x += 1;
    }
  • slice slice normalize

     
    var x = 0;
    var TOTAL_STRINGS = window.TOTAL_STRINGS;
    var data = window.data;
    while (x < TOTAL_STRINGS) {
      const str = data[x];
      const url = str.slice(-1) === "/" ? str.slice(0, -1) : str;
      x += 1;
    }
  • lastIndexOf slice normalize

     
    var x = 0;
    var TOTAL_STRINGS = window.TOTAL_STRINGS;
    var data = window.data;
    while (x < TOTAL_STRINGS) {
      const str = data[x];
      const url = str.lastIndexOf("/") === str.length - 1 ? str.slice(0, -1) : str;
      x += 1;
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    regex replace normalize
    endsWith slice normalize
    slice slice normalize
    lastIndexOf slice normalize

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 11 months ago)
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Chrome 125 on Linux
View result in a separate tab
Test name Executions per second
regex replace normalize 75.7 Ops/sec
endsWith slice normalize 109.7 Ops/sec
slice slice normalize 96.4 Ops/sec
lastIndexOf slice normalize 65.6 Ops/sec