Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
startsWith vs include vs substring vs Array.from
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:146.0) Gecko/20100101 Firefox/146.0
Browser:
Firefox 146
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
4 months ago
Test name
Executions per second
JS startsWith
6010.9 Ops/sec
JS includes
6616.9 Ops/sec
JS substring
3303.6 Ops/sec
Array.from
107.4 Ops/sec
Script Preparation code:
window.prefix = "!"; const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 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; } window.allStrings = []; for (let i = 0; i < 1000; i++) { allStrings.push(window.prefix + makeRandomString(1000)); allStrings.push(makeRandomString(1000)); }
Tests:
JS startsWith
window.allStrings.forEach(s => { s.startsWith(window.prefix); })
JS includes
window.allStrings.forEach(s => { s.includes(window.prefix); })
JS substring
window.allStrings.forEach(s => { s.substring(0, window.prefix.length) === window.prefix; })
Array.from
window.allStrings.forEach(s => { Array.from(s)[0] === window.prefix; })