Script Preparation code:
AخA
 
function compareEndsWith(val, comparator) {
  return val.endsWith(comparator)
}
function compareEndsWith2(val, comparator) {
  return val.endsWith(comparator, comparator.length)
}
function compareSliceMethod(val, comparator) {
  const thingToCompare = val.slice(-comparator.length)
  return thingToCompare === comparator
}
Tests:
  • endWith

     
    const value = Math.random().toString().padEnd(20,'0');
    const ending = "asdf"
    compareEndsWith(value, ending)
  • slice

     
    const value = Math.random().toString().padEnd(20,'0');
    const ending = "asdf"
    compareSliceMethod(value, ending)
  • endsWith2

     
    const value = Math.random().toString().padEnd(20,'0');
    const ending = "asdf"
    compareEndsWith2(value, ending)
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    endWith
    slice
    endsWith2

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36
Chrome 115 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
endWith 4070914.8 Ops/sec
slice 4664534.0 Ops/sec
endsWith2 4130641.2 Ops/sec