Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
CharAt vs subscript ( [] ) in Javascript String
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/117.0.0.0 Safari/537.36
Browser:
Chrome 117
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
CharAt (0)
412316.9 Ops/sec
[0]
414105.2 Ops/sec
CharAt (n)
419110.2 Ops/sec
[n]
420768.9 Ops/sec
charAt(len-1)
404988.8 Ops/sec
[len-1]
419031.5 Ops/sec
Script Preparation code:
const str = "Hello World";
Tests:
CharAt (0)
const str = "Hello World"; console.log(str.charAt(0))
[0]
const str = "Hello World"; console.log(str[0])
CharAt (n)
let n = 5; const str = "Hello World"; console.log(str.charAt(n))
[n]
let n = 5; const str = "Hello World"; console.log(str[n])
charAt(len-1)
const str = "Hello World"; let len = str.length; console.log(str.charAt(len-1))
[len-1]
const str = "Hello World"; let len = str.length; console.log(str[len-1])