Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
JavaScript Checking That A String Starts With A Value - Value Is **NOT** Found - Benchmarks - Playground
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Browser:
Chrome 122
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Value Not Found - string.startsWith method
106.3 Ops/sec
Value Not Found - string.indexOf method
3023.9 Ops/sec
Value Not Found - string.search method
43.2 Ops/sec
Value Not Found - string.match method
121.8 Ops/sec
HTML Preparation code:
<div></div>
Script Preparation code:
const iterationNum = 250000; const possible = "ACDEFGHIJKLMNOPQRSTUVWXYZ0123456789acdefghijklmnopqrstuvwxyz"; // The letter B (and b) is removed const possibleLen = possible.length; function getRandomIntInclusive(max, min = 1) { const minCeiled = Math.ceil(min); const maxFloored = Math.floor(max); return Math.floor(Math.random() * (maxFloored - minCeiled + 1) + minCeiled); // The maximum is inclusive and the minimum is inclusive } function makeRandomString(len, defaultWord = '') { let text = defaultWord; for(let i = 0; i < len; i++) { text += possible.charAt(getRandomIntInclusive(possibleLen, 0)); } return text + defaultWord; } const testWord = window.testWord = makeRandomString(getRandomIntInclusive(10)) + 'Bb'; // B or b shouldn't be in any generated word const allStrings = window.allStrings = new Array(iterationNum); const numberOfStrings = window.numberOfStrings = iterationNum; for(let i = 0; i < numberOfStrings; i++) { allStrings[i] = makeRandomString(getRandomIntInclusive(20), testWord); }
Tests:
Value Not Found - string.startsWith method
let x = 0; const numberOfStrings = window.numberOfStrings; const allStrings = window.allStrings; const testWord = window.testWord; while (x < numberOfStrings) { const str = allStrings[x]; str.startsWith(testWord); x += 1; }
Value Not Found - string.indexOf method
let x = 0; const numberOfStrings = window.numberOfStrings; const allStrings = window.allStrings; const testWord = window.testWord; const testWordLen = testWord.length; while (x < numberOfStrings) { const str = allStrings[x]; str.indexOf(testWord) === 0; x += 1; }
Value Not Found - string.search method
let x = 0; const numberOfStrings = window.numberOfStrings; const allStrings = window.allStrings; const testWord = window.testWord; const testWordLen = testWord.length; while (x < numberOfStrings) { const str = allStrings[x]; str.search(testWord) === 0; x += 1; }
Value Not Found - string.match method
let x = 0; const numberOfStrings = window.numberOfStrings; const allStrings = window.allStrings; const testWord = window.testWord; const testWordRegExp = new RegExp(`^${testWord}`); while (x < numberOfStrings) { const str = allStrings[x]; str.match(testWordRegExp); x += 1; }