Script Preparation code:
AخA
 
const strings = [ 'onclick', 'onwheel', 'onresize', 'noclick', 'nowheel', 'noresize' ];
function getStrings() {
  return strings;
}
Tests:
  • regex

    x
     
    const regex = /^on/
    for( let i = 0; i < 10000; i++ ) {
        getStrings().forEach( str => regex.test( str ) );
    }
  • slice

     
    for( let i = 0; i < 10000; i++ ) {
        getStrings().forEach( str => str.slice(0, 2) === 'on' );
    }
  • array

     
    for( let i = 0; i < 10000; i++ ) {
        getStrings().forEach( str => str[ 0 ] === 'o' && str[ 1 ] === 'n' );
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    regex
    slice
    array

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one month ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Chrome 133 on Windows
View result in a separate tab
Test name Executions per second
regex 613.4 Ops/sec
slice 7282.7 Ops/sec
array 2431.9 Ops/sec