Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Javascript string.endsWith vs string.slice and triple equal checking vs hardcoded index and triple equal, comparing a single character
(version: 1)
Comparing performance of:
endWith vs slice vs hardcoded index
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
const value = "ABCDEF...WXYZ" const ending = "Z" function compareEndsWith(val, comparator) { return val.endsWith(comparator) } function compareSliceMethod(val, comparator) { const thingToCompare = val.slice(-1) return thingToCompare === comparator } function compareByIndex(val, comparator) { return value[12] === comparator }
Tests:
endWith
const value = "ABCDEF...WXYZ" const ending = "Z" compareEndsWith(value, ending)
slice
const value = "ABCDEF...WXYZ" const ending = "Z" compareSliceMethod(value, ending)
hardcoded index
const value = "ABCDEF...WXYZ" const ending = "Z" compareByIndex(value, ending)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
endWith
slice
hardcoded index
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3.1 Safari/605.1.15
Browser/OS:
Safari 18 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
endWith
66832708.0 Ops/sec
slice
334994592.0 Ops/sec
hardcoded index
415152960.0 Ops/sec
Related benchmarks:
wefiowjfoiewjfoiwef
Javascript string.endsWith vs string.slice and tripple equal
test Javascript string.endsWith vs string.slice and tripple equal
Javascript string.endsWith vs string.slice and triple equal
Javascript string.endsWith vs string.slice and triple equal 2
int vs string comparison sdgsg
Javascript string.endsWith vs string.slice and tripple equal (one char)
simple int vs string vs boolean comparison
Javascript string.endsWith vs string.slice and tripple equal checking single character
Comments
Confirm delete:
Do you really want to delete benchmark?