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