Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
startsWith vs str[0] === char
Testing some things
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 17_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/120.0.6099.101 Mobile/15E148 Safari/604.1
Browser:
Chrome Mobile iOS 120
Operating system:
iOS 17.1
Device Platform:
Mobile
Date tested:
2 years ago
Test name
Executions per second
.startsWith
1037.8 Ops/sec
str[0]
6792.9 Ops/sec
HTML Preparation code:
<div></div>
Script Preparation code:
window.regex = /^test/; window.match = 'test'; var data = window.data = []; const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; var TOTAL_STRINGS = window.TOTAL_STRINGS = 100000; function makeRandomString(len) { var text = ""; for( var i=0; i < len; i++ ) { text += possible.charAt(0); } return text; } while (data.length < TOTAL_STRINGS) { data.push(makeRandomString(1)); }
Tests:
.startsWith
var x = 0; var TOTAL_STRINGS = window.TOTAL_STRINGS; var data = window.data; var match = window.match; while (x < TOTAL_STRINGS) { const str = data[x]; match.startsWith(str); x += 1; }
str[0]
var x = 0; var TOTAL_STRINGS = window.TOTAL_STRINGS; var data = window.data; var match = window.match; while (x < TOTAL_STRINGS) { const str = data[x]; match[0] === str[0]; x += 1; }