Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
startsWith vs include vs substring vs Array.from
(version: 1)
Comparing performance of:
JS startsWith vs JS includes vs JS substring vs Array.from
Created:
one year ago
by:
Guest
Jump to the latest result
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; })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
JS startsWith
JS includes
JS substring
Array.from
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:146.0) Gecko/20100101 Firefox/146.0
Browser/OS:
Firefox 146 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
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
Related benchmarks:
.startsWith vs .charAt for single character
.endsWith vs .charAt for single character
.endsWith vs .charAt for single char
startsWith vs include
startsWith vs include vs substring
.startsWith vs .charAt vs str[0] for single character
startsWith vs substr
startsWith vs slice vs substring
.startsWith vs .charAt vs .charCodeAt for single character
Comments
Confirm delete:
Do you really want to delete benchmark?