HTML Preparation code:
AخA
 
1
<div></div>
Script Preparation code:
x
 
window.regexStart = /^test/;
window.regexEnd = /test$/;
window.match = 'test';
window.matchLength = window.match.length;
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;
}
while (data.length < TOTAL_STRINGS) {
  data.push(makeRandomString(getRandomInt(20)));
}
Tests:
  • regex start

     
    var x = 0;
    var TOTAL_STRINGS = window.TOTAL_STRINGS;
    var data = window.data;
    var regex = window.regexStart;
    while (x < TOTAL_STRINGS) {
      const str = data[x];
      regex.test(str);
      x += 1;
    }
  • startsWith

     
    var x = 0;
    var TOTAL_STRINGS = window.TOTAL_STRINGS;
    var data = window.data;
    var match = window.match;
    while (x < TOTAL_STRINGS) {
      const str = data[x];
      str.startsWith(match) === 0;
      x += 1;
    }
  • regex end

     
    var x = 0;
    var TOTAL_STRINGS = window.TOTAL_STRINGS;
    var data = window.data;
    var regex = window.regexEnd;
    while (x < TOTAL_STRINGS) {
      const str = data[x];
      regex.test(str);
      x += 1;
    }
  • endsWith

     
    var x = 0;
    var TOTAL_STRINGS = window.TOTAL_STRINGS;
    var data = window.data;
    var match = window.match;
    while (x < TOTAL_STRINGS) {
      const str = data[x];
      str.startsWith(match) === 0;
      x += 1;
    }
  • indexOf start

     
    var x = 0;
    var TOTAL_STRINGS = window.TOTAL_STRINGS;
    var data = window.data;
    var match = window.match;
    while (x < TOTAL_STRINGS) {
      const str = data[x];
      str.indexOf(match) === 0;
      x += 1;
    }
  • indexOf end

     
    var x = 0;
    var TOTAL_STRINGS = window.TOTAL_STRINGS;
    var data = window.data;
    var match = window.match;
    var length = window.matchLength;
    while (x < TOTAL_STRINGS) {
      const str = data[x];
      str.indexOf(match) === str.length - length;
      x += 1;
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    regex start
    startsWith
    regex end
    endsWith
    indexOf start
    indexOf end

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 days ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Chrome 136 on Windows
View result in a separate tab
Test name Executions per second
regex start 569.8 Ops/sec
startsWith 1370.3 Ops/sec
regex end 289.5 Ops/sec
endsWith 860.9 Ops/sec
indexOf start 10606.7 Ops/sec
indexOf end 11877.0 Ops/sec