Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Javascript string.endsWith vs string.slice and triple equal checking vs hardcoded index and triple equal, comparing a single character
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.4 Mobile/15E148 Safari/604.1
Browser:
Mobile Safari 18
Operating system:
iOS 18.4.1
Device Platform:
Mobile
Date tested:
one year ago
Test name
Executions per second
endWith
73705416.0 Ops/sec
slice
453073856.0 Ops/sec
hardcoded index
456867200.0 Ops/sec
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)