Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
char index vs charAt() vs slice()
Compare methods for testing string's beggining character.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/118.0
Browser:
Firefox 118
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
2 years ago
character index
174.5M/s
charAt()
157.8M/s
slice()
128.8M/s
View exact numbers
Test name
Executions per second
✓
character index
174,500,560 Ops/sec
charAt()
157,840,560 Ops/sec
slice()
128,754,256 Ops/sec
Script Preparation code:
var str = 'foo bar baz'; var noop = Function.prototype;
Tests:
character index
if (str[0] == 'f') noop();
charAt()
if (str.charAt(0) == 'f') noop();
slice()
if (str.slice(0, 1) == 'f') noop();