Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
wefiowjfoiewjfoiwef
(version: 0)
Compare methods for testing string's beggining character.
Comparing performance of:
character index vs charAt() vs startsWith() vs slice() vs RegExp
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var str = '!foo bar baz'; var noop = Function.prototype;
Tests:
character index
if (str[0] === '!') noop();
charAt()
if (str.charAt(0) === '!') noop();
startsWith()
if (str.startsWith('!')) noop();
slice()
if (str.slice(0, 1) === '!') noop();
RegExp
const pattern = /^!/; if (pattern.test(str)) noop();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
character index
charAt()
startsWith()
slice()
RegExp
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:
char index vs charAt()
char index vs charAt() for non-zero index
char index vs charAt() vs slice() with Object
char index vs charAt() for the first character
Comments
Confirm delete:
Do you really want to delete benchmark?