Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
.startsWith vs .indexOf vs index
(version: 0)
fork of https://www.measurethat.net/Benchmarks/Show/975/11/regex-vs-indexof-vs-startswith-vs-substr
Comparing performance of:
startsWith vs indexOf start vs Index
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<div></div>
Script Preparation code:
window.regexStart = /^test/; window.regexEnd = /test$/; window.match = 'test'; window.matchLength = window.match.length; var data = window.data = []; const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; var TOTAL_STRINGS = window.TOTAL_STRINGS = 100000; 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; } while (data.length < TOTAL_STRINGS) { data.push(makeRandomString(getRandomInt(20))); }
Tests:
startsWith
var x = 0; var TOTAL_STRINGS = window.TOTAL_STRINGS; var data = window.data; var match = window.match; var count = 0 while (x < TOTAL_STRINGS) { const str = data[x]; if(str.startsWith(match)) count++ x += 1; }
indexOf start
var x = 0; var TOTAL_STRINGS = window.TOTAL_STRINGS; var data = window.data; var match = window.match; var count = 0 while (x < TOTAL_STRINGS) { const str = data[x]; if(str.indexOf(match) === 0) count++; x += 1; }
Index
var x = 0; var TOTAL_STRINGS = window.TOTAL_STRINGS; var data = window.data; var match = window.match; var count = 0 while (x < TOTAL_STRINGS) { const str = data[x]; if(str[0] === match) count++; x += 1; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
startsWith
indexOf start
Index
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
Some vs. Filter vs. indexOf vs findIndex
Includes vs. IndexOf vs. Filter vs. Find vs. FindIndex vs. Some
Some vs. Filter vs. indexOf vs includes1123123123
Some vs. Filter vs. indexOf vs. includes (string version)
easd Some vs. Filter vs. indexOf vs. includes
Comments
Confirm delete:
Do you really want to delete benchmark?